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 => 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.
Your situation is similar to "my contact switched to Android, but all of my texts are continuing to send via iMessage rather than SMS":
- Contact switched to Android; how to send texts instead of iMessages?
- How do I disable iMessage for a contact who no longer has an iPhone
In your case though it's a positive. iMessage delivery will continue until/unless your contact deregisters their number from iMessage — even if they swap SIMs.