How do you deal with an enemy pilot on your titan?
Solution 1:
If you have enough of your core bar charged, you can use the counter rodeo measures, which deploys your electric smoke. This won't stop the pilot outright, but if you react quickly enough, it typically can get them down to 10% HP.
If you're near allies, they can shoot off the pilot and a friendly titan can just melee them to insta-kill them. Granted, the best thing to do is not get rodeo'd at all.
To do that, try to avoid high buildings/walls, as pilots need to attack from above to rodeo. If they drop down, it's much harder to spot them. If you do spot a pilot trying to get on you, a titan melee can one-shot them and titan guns can usually 1 - 2 shot pilots, with the exception of legion.
Solution 2:
If there is a pilot on your titan, then you should endeavor to kill them as efficiently as possible. It is important to consider the risks of a pilot being on your titan.
Pilots have a limited set of tools available to them for rodeo'ing titans. They can pull out a battery (which will remove one of your 4 life bars), they can also (if a battery was previously removed) toss a grenade in the empty battery slot. While losing some life is rough, if you are "DOOMED" as a titan and catch a grenade in one of those slots it can blow both you and the titan up right then and there.
So, with all of that to consider from pilot risks, it is important to first weigh the risk dealing with this pilot poses versus all of the other threats that are presented on the battlefield.
The easiest way I have found is using the electric smoke anti pilot tactical attack that titans have. It is very damaging, and if you use it then spin a little in your titan the pilot will almost always get turned around as well and die even if they try to disembark.
If that is not an option, then having someone else scrape them off is nice, although this basically never happens unless you are on microphone with a teammate.
So, if there is no one around to help, and you just got in your titan and cannot use your ordinance (smoke) then there are two options. Get out and try your luck killing the other pilot (my favorite - they often don't think this will happen); or, wait until they jump off and kill them then take the battery pack back.
The battery pack will look like a small rectangular green object on the ground. You can plug it back into your titan by disembarking, grabbing it (running over it - no need to hold down X), and then simply getting back in your titan. As you get in, the benefit (a small overshield and partial health) will show.
Overall, the very best strategy for dealing with pilots in your titan is to avoid their proximity. Avoid being in narrow areas that allow easy jump access, and avoid being in the center of an area that has a lot of roofing around it. Pilots can be especially deadly to titans when they are in number, and 3 will most certainly take a titan down very quickly in an open area where they have the cover and high ground.