Actually, no the AppleID is not irrelevant to iMessage, as it will not work without one. When you activate iMessage (and it requires facetime to also be active) it associates your phone number with the AppleID of the device (or a different one if you deliberately change the AppleID in message settings). By default, the primaty "receive at" mobile addresses for the iMessage account are the phone number and emails tied to the AppleID. Note that it pulls the phone number from the phone itself, not the account (I noticed this when I set it up - my AppleID account only has my google voice number, not my real cell phone numbrer, but iMessage pulled my cell number from the phone and entered that in the phone number field in settings).
To actually send messages it uses the phone number as a primary account ID or the email associated with the same AppleID now tied to the number (both options are obviously necessary since iMessage supports devices other than phones, like the iPod Touch).
When you put your SIM in that phone, it would have had to have iMessage already active on it. But, it took the number from your SIM and associated it with the primary account ID which was whatever AppleID iMessage was set up with. Your phone number and that AppleID were now registered with Apple's messaging servers as a linked account ID for iMessage,
By disabling the iMessage option on another iOS 5 enabled phone, you switched the iMessage services associated with the number off, but I assure that number was linked to an AppleID - you cannot activate iMessage without a valid AppleID. You can think of the AppleID as the primary account ID, and the phone number and any emails listed in message settings as the associated account addresses.
Anyhow, glad you got it fixed.