>>42994515The Gengar appeared several episodes ago and haunts the lab that Ash works in. Ash yelled at it, so Gengar hid itself in his shadow and cursed him for lolz. Ash later leaves the lab to jog and relieve stress, with Gengar surprised and upset, still in his shadow. Ash bumps into Gengar's trainer, who left it at the lab three years prior, before it even became a lab.
It's revealed that Gengar was basically waiting at the property for three years after his trainer told him to wait there. It haunted the building to scare away people, but Sakuragi lacking fear and common sense opened his lab there anyways, resulting in Ash and Go eventually living there as assistants.
The trainer, having been cursed and terrified of Gengar basically insults it due to his girlfriend teasing him over tripping which pisses Gengar off, realising it was abandoned this entire time. It flees, TR tries to recruit it but it disagrees, Ash saves it from their Ghostbusters tech and then Ash and Gengar blasted them away with Gengar deciding to trust Ash, Ash having earned it.
None of that is contrived or 'random'. The two episodes build up its character, its existence outside of Ash's life, its reasoning for its anger and hauntings and why it chose Ash as its trainer. The episode also hints its issues aren't resolved, considering the narrator questions if Gengar is done with its malicious antics.
Overall, Gengar and Dragonite are both well-established characters, with good backstories, good motivations and reasonable justification to join Ash.