Let's approach these concerns one at a time.
I understand you made an iTunes purchase but you are unable to download it on the Yosemite iMac. Can you view your iTunes Account using its Account menu > View My Account... ? It should prompt for your Apple ID password. If that does not happen, describe what happens instead.
Try Account > Sign Out and then try signing in again. Describe what happens.
- For example, on one very old Mac, I occasionally encounter a dialog alleging my iTunes session has expired, and it prompts me to sign in again. I provide the Apple ID credential only to encounter the exact same dialog again. Again and again. That may repeat six or eight times in succession, which is obviously annoying, but it eventually relents. Who knows why that happens but I have been purchasing iTunes content since its inception a couple decades ago. The annoyance only occurs on older Macs running older OS X versions and Apple stopped caring about them long ago.
System preferences >>> iCloud does not generate the code ...
I'm not sure it's supposed to, so it's not clear to me what you're expecting there.
All my devices new and old were working until Mail stopped working (for one of the three accounts in Mail) and this random request to log into my AppleID was requested.
If you are not receiving email messages from one particular account, the gold standard for fixing that is to delete the problematic email account(s) and add them again. Refer to If you can’t send or receive email on Mac - Apple Support, under Remove your email account, then add it back. If you determine you are unable to add that account again, it is likely the particular email account server will no longer function under Yosemite. For example, I happen to know it is no longer possible to add "newer" Microsoft Exchange server hosted email accounts to "older" OS X versions of Mail. One day they simply stopped working. The same may be true of other email services. We're just out of luck in that case.