Does iMessage work internationally with only a number? My friend and I have a sim from say country A. If my friend goes to country B and temporarily uses a sim from country B (I.e. not data roaming with the original sim), can I still use iMessage given that I only have the original number from the country A sim?
Yes, you can still use iMessage in this case.

The phone number used in country A is registered with Apple's servers, so when you use iMessage to message that number, they'll send the message to the devices logged in to iCloud with the account that has that phone number registered for iMessage.

Your friend can register multiple such numbers, and from the Settings =&gt; Messages on his iOS device choose which numbers to actually use for sending and receiving.

If your friend does not want this to be possible, he needs to deregister his phone number from iMessage. He can do that by following this guide from Apple.