When you enter the allied creature's space, you have to have an exit strategy. Something might happen during your turn that negates that strategy, such as caltrops, the Sentinel feat, or being knocked prone, but you can't go in without having a way out.
That said, if your exit strategy gets screwed up or you get forced into somebody's space with no movement left, you're not actually required to do anything to fix it.
So in your case #1, you were somehow forced to occupy the same space during your turn with no movement left (perhaps an enemy creature's reaction had a push effect). You are not required to spend an action to dash. If you had enough movement left to move to any other square, you would be compelled to do so, but nothing requires you to gotake an action (or do anything, for that matter) to get yourself out of your way to fix itthat square (but the DM might decide that being jammed up against your ally brings penalties -- more on that later).
In case #2, you can enter the square with the intent of leaving, and if you fail your save against the caltrops, you're stuck there. The same goes for entering the area of a number of spells such as web or Evard's black tentacles.
In case #3, the only way you can enter the space is if you are somehow unaware of the difficult terrain effect that would prevent you from leaving with your remaining movement, perhaps due to hallucinatory terrain or some such effect. If you don't have a clear way out, you can't go in. By the way, do remember the often-ignored rule from the Difficult Terrain rulessection in the Player's Handbook, page 190:
The space of another creature, whether hostile or not, also counts as difficult terrain.
Your DM might decide to apply a penalty of some sort to two creatures sharing the same space. It's not, strictly speaking, in the rules, but the DM could certainly decide that you both take disadvantage on your attacks and attackers have advantage against you as you get in each other's way.