There is something called benign paroxysmal positional vertigo (BPPV), which really just means the sudden sensation that you're spinning or that the inside of your head is spinning. It happens by specific changes in the position of your head, and it's rarely dangerous, unless it causes falls.
https://www.mayoclinic.org/diseases-conditions/vertigo/symptoms-causes/syc-20370055
You can also get dizzy if something is going on with your ears, like an ear infection, fluid in your ears from swimming, allergies, etc. Ears play a big role in balance.
If it lasts or gets worse, or you have any of the symptoms listed in the article, see your doctor for sure. In the meantime, take it easy and rest.