Taking something that is not yours is really illegal may it be bitcoin or anything that you take without any authority from the owner. In the case you've given wherein you accidentally have bitcoin in your wallet upon generating it and you don't know who gave it then it is not stealing because there is no intention. But a chance of this happening is near to impossible.
Yup, this is a very strange coincidence, the chance of this to happen is one-in-a-billion so it's tricky to tell if this action is illegal or not. And I think we don't have to worry whether this issue is wright or wrong because the OP didn't do anything that could be called against the law.