1. The pit kept Joseph from being killed.
His brothers fully intended to kill him and saw the pit as a way to get rid of him without shedding blood (v.22)
2. God made sure the pit was dry (v.24). If water had been in it, Joseph would have drowned.
3. The pit was used as a holding tank until the Ishmaelite traders came by and escorted him to Egypt (v.25-28). It was no accident that the traders just happened to travel by that route at just the right time. God was leading them (without them knowing it) so they would take His servant to the desired destination. And it was there that the Lord eventually made him a ruler!
Sooner or later, someone is going to throw you into a pit. When it happens, keep in mind that the Lord has a purpose for your pit. Although your enemy had the first word, look for God to have the last word. He is just using your pit as a holding tank to get you to a better place. And He will, if you will keep your heart right and not get bitter at your brothers.
Keep looking up! (Even when you're at the bottom of the pit)