Yeast + Beer = CO2. Bottling the yeast cake = a small amount of CO2 in solution that can gradually equalize pressure with its environment. Shaking CO2 in solution + releasing pressure mechanism (cap) = Explosion of liquid.
In short... yes. You're fine. Use it. All is well. RDWHAHB. Now go focus on brewing that batch.
Next time, don't uncap till you're ready to pitch it. Spray the bottle and the bottle opener both with some StarSan / (insert your sanitizer here), let drip for a moment, then uncap the bottle
directly over the bucket/carboy funnel/etc. Then, the foam goes where you want it to go.
Cheers!
Also - for an easier way, use sanitized 20oz plastic soda bottles, or 1-Liter tonic water bottles (that's what I use) - and leave 2" of headspace. Then you can twist to remove pressure, and quickly re-cap it as you see the mountain of liquid approaching the neck of the bottle. Less mess that way, and you don't waste any bottle caps!
