I'll try my best to make sense of this and my theory as to what happened, but without some exact details we may never know;
First of all, the battle was irrelevant to the trade (but well done for winning!). The results of any battle will never effect a trade you do in the future, so you can rule that out!
First of all was the trade local or over the internet?
Sometimes local trades go a bit goofy and say you can't trade a Pokemon for some reason or another. I traded an Exeggutor onto Y from y X and it wouldn't go back for some reason, I just kept on trying and trading around with different Pokemon until it did, so if it's local that's my advice to you.
Secondly, I'm not sure if the game has any "in game hack check", from the sounds of them being shiny legendaries I'd put money on them being hacked, maybe they're being locked for that reason, but honestly I don't think the game is smart enough for that.
Thirdly, Deoxys and Mew are both classed as "secret legendaries" meaning they were never able to be capture in game without some kind of event, I know these Pokemon are not able to be traded on GTS, so maybe they can't be traded in general. Although I have traded a Meloetta to someone so I can't go by that.
Fourth, Pokemon with HM moves cannot be traded from the Party to another person's game, it needs to be in a box.
How to get around it? Have you tried maybe putting both Pokemon onto one Pokemon Bank account and then putting back onto the games (making a kind of unofficial trade). But of course that only works if you're local, if this is an internet issue then I have no idea.
But yeah, sorry I wasn't more help, that's all the advice I can give without knowing the full details of the issue.