This is what I don't get.
Can anybody explain how this all works in terms of giving away or selling an older computer that has ML installed from the app store?

It is very simple, if the computer originally shipped with Snow Leopard or below the upgrade is tied to Lion and/or ML is tied to your AppleID. Apple is VERY clear about that and states the upgrade may not be transferred. Therefore if you upgraded from SL you MUST re-install SL and if you want give the buyer a $20 credit to buy a license of ML. That's it, nothing more complex about it. If the machine shipped with SL and you want to sell it with Lion or ML then be prepared to give the buyer your Apple ID including your credit card info...obviously a pretty stupid idea.

We're giving away our iMac to a family relative next year when we upgrade to the new iMac and our early '09 iMac came with SL but I have ML installed (purchased with my AppleID).

The thing is I don't have an issue with giving them my machine with ML installed as it's paid for and already on there, not to mention it's more usable and secure than SL; I don't want to hinder them with an old OS. Besides, it's as though they're borrowing my machine to use in which case I'd be crazy to downgrade the OS just for that. However I do want all my data and any Apple ID ties severed with this machine on hand-off.

I know the morality police might attack me for posting this but whatever. What I'm going to do (and OP can do too) is use Lion Disk Maker (link) which works great to create a bootable ML (or Lion) installation disk on a USB drive. I've already done it and it works great. What it does after creating the USB drive image is allow you to install ML/Lion on your machine from USB drive, do a complete wipe and clean install without any ties to your Apple ID. So all your data is gone, a fresh install of OSX and no Apple ID info required.

All you need for this is to re-download the ML (or Lion if you prefer) from the Mac App Store (they'll be in your Purchases tab).

Are you sure your Apple ID isn't imbedded within the ML image you used to create the bootable USB installer, and thus is on the USB drive, and again on any computer you use that USB installer with?

As far as I could tell, that's not the case. After the install completes it asks to enter a new Apple ID (or a split Apple ID for iTunes and iCloud) and in my test install I entered my wife's ID instead of mine and the system was set up based on hers and there was no sign of anything to do with my ID.

As far as I could tell, that's not the case. After the install completes it asks to enter a new Apple ID (or a split Apple ID for iTunes and iCloud) and in my test install I entered my wife's ID instead of mine and the system was set up based on hers and there was no sign of anything to do with my ID.

I sold my iMac with Mountain Lion installed, in part because my children apparently absconded with my Leopard/Snow Leopard install discs. I'm sure they're somewhere in our house, but I have no idea where.

As a slightly OCD person, after selling it I had all sorts of concerns about security (such as: "did the disk utility on the LionDiskMaker install actually delete the drive?" despite taking hours to do its three passes)

And then, after the transaction, the question of whether the buyer would have access to my Apple ID. When installing you have the option not to set up an Apple ID (skip this step) so the computer, as sold, was set up without. Even if my ID is somehow linked to the Mountain Lion install, it's ultimately my email address -- not much to be done with that without authentication.

Yes, I had to think these things through thanks to some very unhealthy OCD paranoia

I'm sure I may have violated the EULA, but ultimately this installation of the operating system was bought and paid for and it's not going to be installed anywhere else.