Ilbranteloth
Explorer
So you'd be OK with frenemies? (Two necromancers that send their animated dead to attack the other guy every day?)
XP is a game construct that doesn't really exist within the game world itself. It is up to the DM to determine what constitutes activities within the setting worthy of gaining XP in the game. The rules do not define the setting/game world. They are an out of setting tool to help a DM consistently and fairly adjudicate action within that world.
In my game you can almost always be assured that if you're trying to find loopholes in the rules, which are a framework to help me as a DM adjudicate the action in the world, that I will opt to close the loopholes rather than entertain this sort of nonsense. Sure, it's fun to look for the endless ways that strict adherence to game rules create absurd situations. But that sort of "fun" doesn't actually enter my game.
Of course, I'm assuming that when you posted the OP and follow-ups that you already knew that the answer from the vast majority of DMs would be, "no."