There is a rule in the "Moving Around Other Creatures" section which states:
Whether a creature is a friend or an enemy, you can't willingly end your move in its space…
I am wondering just how absolute this rule is and have come up with example situations where its application is unclear to me:
On your turn, you are forced to occupy the same space as another creature, you have no more movement available, but you still have your action or bonus action available. Are you required to take the Dash action or to use some method (such as casting misty step) to get you out of the creature's space?
Any creature that enters the area must succeed on a DC 15 dexterity saving throw or stop moving and take 1 piercing damage. Until the creature regains at least 1 hit point, its walking speed is reduced by 10 feet. A creature moving through the area at half speed doesn't need to make the saving throw.
An adjacent creature in standing on top of caltrops, and you only have 15 speed (and 15 movement left). I believe that you could not walk through them at half speed as you would run out of movement and be stuck in the creature's space.
However, could you walk through them normally even though they have a chance of having your move stop in the creature's space (which, presumably, the character would know about, and thus would make it a willing decision)?
Everything is difficult terrain, there is an adjacent creature, and you have 15 feet of movement left, could you move onto the creature's space and then realize you can't leave that space (as you don't have enough movement to do so)?
I believe that my question is different from this one in a few ways. My second and third examples involve more willingly ending your move in another creature's space (at least to me they seem to be more willingly done) and my first example calls into question what happens when the creature still has a way to gain the ability to leave the creature's space (such as by taking the Dash action or casting misty step) which the linked question did not mention or address.
Does the rule preventing you from ending your turn in another creature's space force you to take certain actions?
The rule requires that you not willingly end your turn in another creature's space. Sometimes you will be prevented from taking actions in order to make sure the rule holds true.
The DM always has jurisdiction over edge-cases like this and will often make rulings on consequences and benefits, so although I speak from the perspective of being a DM myself, my own interpretations will not always hold true.
Willing and unwilling do not have mechanical definitions, but here's how I would rule them for practical use.
Regarding your examples:
You must not willingly spend movement to end in the creature's space. In the case that they're forced unwillingly into the space after/before movement, such as by a grapple, RAW does not require action economy (misty step, breaking grapples, dashes, etc) to be spent on vacating the space.
This is a tougher one to rule on. RAW you can attempt to spend movement to pass through the space and unwillingly have your movement reduced to 0 in that space. The creature must be friendly or your size class has to permit movement through it's space (size class overrules this general rule).
This would likely require a rollback. You willingly spent movement and then realized it was movement you couldn't use. You broke a rule, the DM will likely undo the action that broke it or offer you an alternative (such as taking disadvantage).