Up to the GM
The rules do not specifically provide for the situation you describe, and so the GM must make a ruling, or several.
A very reasonable course of action is for the GM to allow it, but require one or more ability checks.
As said in the Basic Rules:
When you describe an action not detailed elsewhere in the rules, the DM tells you whether that action is possible and what kind of roll you need to make, if any, to determine success or failure.
Discuss it with the GM
A smart player will discuss with the GM what they want to accomplish, and work out if and how it's possible, and how hard it might be.
The GM determines the results
The GM could just say, yes, that will work, or no you can't do that. Or, the GM might discuss with the player at some level of detail the various steps involved and the challenges each presents.
Different GMs and different tables can handle this differently and still be within the rules. Some GMs, really wanting to keep the play moving, could easily just say yes that will work, or no it won't.
Or they could "that's going to be really hard, if you want to do it, make a Dex check to see if you can position yourself correctly and another Dex check to see if you can grab on."
Another GM and another table may want to carefully inspect every aspect and make individual rulings.
Players will always want to do things that don't fall within the rules. That's good! Examining every aspect in minute detail then and there, while in some ways interesting, can really bog down the game. Often players not involved in the specific discussion quickly lose interest, and combats take way too long.
I am usually inclined to make the quickest judgement I can, and if necessary, pull it apart after the session to better understand it for future similar encounters.
Breaking it down
If the GM wants to break it down into individual steps, these are some considerations.
The initial teleport
The dimension door spell says you arrive "exactly at the spot". However, the spell makes no reference to teleporting directly onto a creature, just as it makes no reference to arriving standing if you are prone, or any sort of tricksy use of the spell involving specific body position, so the GM must adjudicate.
Directly teleporting onto a moving ally
Directly teleporting onto a moving ally? Probably extremely difficult, almost impossible, very likely to end in force damage and a failed teleport. The GM could adjudicate an ability check on how hard it is to teleport directly onto a moving ally while changing your body shape to conform to that, and the risk of misjudging and intersecting, or the GM could just tell the player that they can try, but it's almost or even certainly going to end in failure.
Teleporting above an ally
Teleporting above and trying to grab on? Still pretty challenging, but maybe doable, with some good rolls. The challenge is that the spell does not cover body position, so it's reasonable for the GM to allow it, but require a Dexterity check on body positioning as the caster teleports above the target. The GM would need to determine the DC, perhaps considering factors such as terrain or lighting. Have these two ever tried this stunt before? Probably not, but if so, that might really help. Does the caster have an opportunity to tell the ally what he's about to attempt? Probably not, but if so, that could help, too. Is the ally moving, fighting, petrified? All of these are important factors.
You also mentioned the "in a place already occupied" phrase of the spell. To my reading, that describes what happens if the bodies literally intersect on arrival, not space effectively controlled, but a GM could read it differently.
Grabbing On
What rules are close to describing "riding on a friend's shoulders"?
Neither the mounted combat rules nor the grappling rules describe teleporting onto a friend's shoulders in the middle of combat.
However, an ability check is very reasonable. Again, there are many situational factors that the GM can choose to consider: lighting, positioning, other things going on.
The GM might want to use degrees of failure, which can really help adjudicate these sorts of stunts quickly and in a fun way. Maybe the caster succeeds in grabbing on, but puts their hand over one of their ally's eyes, potentially giving the ally disadvantage.
https://www.dndbeyond.com/sources/dmg/running-the-game#DegreesofFailure
Staying There
Here's a problem. The Movement rules say:
Whether a creature is a friend or an enemy, you can't willingly end your move in its space.
The GM must adjudicate this. If the GM approaches this in a mechanistic way, then the stunt becomes impossible. To me, it's the GM's job to decide when these rules need to be broken. Is there a rule that says, "On the other hand, you CAN end your move in another creature's space if you've teleported onto its back"? Of course not. However, it's perfectly within the GM's rights to allow it in this circumstance.
I'll note that in this circumstance, you aren't ending your movement in another creature's space, but instead ending up there via spell. Maybe that makes a difference, maybe not.
Some players will immediately latch on to this and either claim that the GM is not following rules-as-written, OR will start looking to exploit this stunt as a precedent. As a GM I would say, "Yep, you're right, I am allowing this character in this circumstance to end its turn willingly end its turn in another creature's space. Yes, you're welcome to propose similar shenanigans. No, I'm not promising it will work. Out of session, you're welcome to propose a home rule to me, if you want, otherwise, I'll continue to adjudicate on a case-by-case basis. And, by the way, I make these sorts of decisions constantly, it's just that you don't usually notice them."
The Second Teleport
This is probably pretty easy to adjudicate. If the ally is conscious and willing and the size of the caster or smaller, the caster should be able to cast dimension door and get them out.
Putting it all together
The scenario might play out like this.
GM: Wendy, it's your turn, what do you do?
Wendy the Wizard: Joe the Fighter is pinned and hurt, and if we don't get him away from those devils he's a goner. Can I dimension door onto his shoulders, then next turn dimension door us both out?
GM: That's pretty crazy. If you try to dd directly onto Joe's shoulders, you know there's a very high likelihood that you'll dd into Joe, especially given how he's moving around, and if that happens you'll take damage and the dd will fail. You can try dding to right above Joe, then grabbing on. You won't be on his shoulders, but you can try to land on his back. This is crazy though. He doesn't know you're about to do this, there's all kinds of stuff going on. You'll need to make a Dex check just to position yourself in a favorable position in the air, and another one to grab on. Then you're going to have to hang on for a whole round, so you might need a Strength or Dex check later just to hang on. I'll tell you straight up this could really go sideways. You make bad rolls here and you could easily end up with both you and Joe on the ground and entangled with each other. Are you sure you want to do it?
Wendy: [opens web pages and starts arguing]
GM: I don't want to bog down the game. If you want to do it, give it a try. Or do something else. We can discuss the fine points out of session.
Wendy: Okay, I'll try to teleport above him. Right before I cast I'm gonna yell "Joe, incoming! I'm gonna land on your back and teleport us out of here!" I cast. I rolled an 18 for the first Dex check!
GM: You're pretty impressed with yourself as you materialize just above Joe and start to drop. Joe, you heard Windy call out and you don't know what's going on, but you brace for impact. Wendy, you think it was smart calling out like that; maybe it gave Joe a clue and improved the chances of this stunt working. Now make a Strenth or Dex roll, your choice, to grab on.
Wendy: Dex. Oh no, a 2! That's not good! I use my inspiration. A 12! What happens?!
GM: You land but one of your feet goes astray, and in compensating, you grab Joe's head. One of your hands is in front of one of Joe's eyes, and he's staggering a bit from the impact.
Wendy: Okay, I'm going to....
GM: Hold that thought, that's your turn. Joe, with the sudden added weight on your back, and with Wendy's hand over your eye, you'll have disadvantage on your next attack, or, your choice, you can compensate and the next attack against you has advantage instead....
[Battle continues, next round, Wendy dds them to safety.]
In Conclusion
To me, it's important to make the rules serve the game, instead of making the game subservient to the rules.
The Introduction to the DM's Guide is worth reading closely, and keeping in mind. It is every bit as much part of the published rules as the spell definitions. In part it says:
The D&D rules help you and the other players have a good time, but the rules aren’t in charge. You’re the DM, and you are in charge of the game.
Further down in the intro it says this:
The rules don’t account for every possible situation that might arise during a typical D&D session. For example, a player might want his or her character to hurl a brazier full of hot coals into a monster’s face. How you determine the outcome of this action is up to you. You might tell the player to make a Strength check, while mentally setting the Difficulty Class (DC) at 15. If the Strength check is successful, you then determine how a face full of hot coals affects the monster. You might decide that it deals 1d4 fire damage and imposes disadvantage on the monster’s attack rolls until the end of its next turn. You roll the damage die (or let the player do it), and the game continues.
This is very similar to the scenario you described, in that the player wanted to do something unusual, the GM made a ruling, and the game moved on.
Could the GM have had the player with the brazier treat it as an improvised weapon? Maybe? You could spend an hour at the table minutely examining the throwing of the brazier. Or the GM could have said, no that's not in the rules. Or yes you can do it. Instead the GM made a quick ruling, and "the game continues".
In the end, rules lawyers on the Internet can offer opinions, but it's the GM and the other players at the table that actually makes the game come alive. I find making quick rulings and moving the game along is the most fun. Of course, it's also fun to dissect the events after the fact, too.
Happy adventuring!