Yosef was punished with two years additional years in jail because he asked the Sar HaMashkim to mention him to Paroh in the hopes of gaining his freedom. This request, says Chazal constituted a lack of Bitachon. The Meforshim ask that Yosef was merely doing Hishtadlus and trying to procure his freedom through normal ways. Isn't Hishtadlus not only permissible but required? To understand this we must first understand the true meaning of Bitachon and Hishtadlus.
Does Bitachon or reliance on Hashem mean that when I am faced with a problem I must be confident that things will turn out the way I'd like them to? No, says the Chazon Ish. Bitachon is an offshoot of Emuna, and the definition of emuna is that I believe that nothing in this world is by chance and everything is directed by the hand of Hashem. It follows that no matter what situation you face you must believe the outcome is the will of Hashem, and that Hashem can bring any outcome he desires without anything standing in His way.
So back to our question. If I am facing danger I can't know if I will be saved, but I must believe that whatever happens is Hashem's will, and since Hashem only wants what's good for us, whatever happens is by definition good. There is no bad outcome to any problem.
So then what is Hishtadlus? How can my efforts change what Hashem knows is good? One would reason that the only Hishtadlus needed is to daven to Hashem, for everything else is for naught. So why would I work on my behalf at all? The Chazon Ish explains that Hashem wants us to take action that in the eyes of the the world seem to achieve our goals because Hashem wants to run the world according to the laws of nature. Hashem wants to remain hidden as much as possible and not need to reveal His hand in running the world.
This seemingly logical explanation has far reaching implications in dictating how we must behave with regard to Hishtadlus. Since Hishtadlus means achieving our goals in a perfectly natural way, it rules out any action that has only a remote possibility of succeeding. If one takes action that has little chance of working or doesn't make too much sense, that is not Hishtadlus. Once something falls out of the realm of Hishtadlus it becomes an act of desperation and is forbidden since it shows a lack of emuna. It shows that you don't believe Hashem can solve your problem and will do anything to help yourself however remote.
The proper way to solve your problems is to daven to Hashem and hope for his salvation. At the same time you should take normal steps to solve your problem. Anything beyond that is a waste of time and a lack of emuna, so don't take a desperate shot in the dark. It will hurt you spiritually and won't help you come close to your goal even one iota.
Rav Dov Yaffa says that the Chazon Ish explained that this was the charge against Yosef for asking the the Sar HaMashkim to remember him. A minister of the stature of the Sar HaMashkim is not of the nature to return favors by humbling himself and rehashing his shameful past before the king. Yosef's request crossed the line of Hishtadlus and bordered on desperation, and for that he was punished.