Stealing is illegal. Period.
Let's say I generate a new address and by some miracle it has Bitcoin already in it belonging to somebody else. Is it legal to just take it? I understand those odds are very low, no need to lecture me, I'm just interested.
The fact that you ask the question means you need to be lectured on the odds

The odds are designed in such a way that it will not happen. I mean
never ever!
So change the question: what if you manage to copy someone's private key, is it illegal to take the money? Yes of course! But posession of a private key is also the only way to prove ownership. It makes me curious what will happen when two people were to claim the same ownership in front of a judge.