Nintendo has a filter systems on the server and it blocks any illegal Pokemon. So when you get them, they're legal and ready to be used in online battles.
In order to pass the trade, our server will make necessary changes on any illegal setting on the pokemon, including ability, held item, moves, level, met level etc.
Here's a list of items can't trade.
If you set your pokemon holding any of them, you'll get no item when you receive the pokemon.