This is explained somewhere, but if you take a castle as a mercenary you get paid for it but the ownership goes to the king you work for. You're a hired gun, not a baron - was the thinking behind the logic.
I think, at some point I prevented people from becoming mercenaries if they owned castles because it got really weird but might have taken it out.