Apple - What causes a Mac to lose its serial number?
A lack of a visible serial number should not affect your Mac.
Apple does not guarantee a serial number will be set. Technical Note 1103 warns developers not to rely on a serial number being available to uniquely identify a Mac.
The technical note suggests the serial number can vanish if hardware components are changed. Other reasons appear to be possible but Apple does not enumerate every cause:
Caveats for using the serial number
It is possible for a system to lose its serial number so that it will no longer appear either in System Profiler or the I/O Registry. Repairing a system by swapping hardware components is one reason this can happen. Apple does not document the specific details of how a machine can lose its serial number. Once the serial number has been lost there is no means to restore it to the machine.
Apple does not guarantee that all future systems will have a software-readable serial number.
Both of these cases illustrate why asset tracking software should always provide a way for a serial number to be entered manually.
I am not aware of any further documentation about restoring the serial number. If it is possible, this capability is likely to only be available to Apple engineers or support staff.
TUAW has an article on this problem, the author had his logic board replaced and apple did not reset the serial number. In essence he did software trouble shooting, reinstalled the os.... at some point he realized he did not have his serial number. As per a comment Apple or an authorize service providers have software that is able to reapply serial numbers and he was able to connect with messages. The link to the story is below.
http://www.tuaw.com/2013/01/14/if-messages-on-os-x-cant-connect-check-your-serial-number/
My girlfriend's 2009 white MacBook lost it's serial number after upgrading to OS X El Capitan. Didn't realise this until it refused to log in to iCloud, AppStore etc. and started digging around.
I can say that even though Apple won't admit or explain why this happens, I know every change made to this machine. After 4 months the keyboard became buggy and would randomly lock the RETURN key in repeat. They changed the logic board under warranty and it's been fine since. I suspect this is the cause.
I have added more RAM myself (Approved Kingston RAM, but not from Apple), and I've recently replaced the HDD with an SSD. However I have done this to several different macs without issues, so I suspect that the logic board replacement was the cause.
What was worse? We had the rubber base replaced under warranty (Apple admitted there were manufacturing issues where it would start to peel off) but of course the replacement base was without a serial number printed on it! By a stroke of luck and several hours of searching I found the support case online for the machine and luckily the serial number was registered there! Phew - we almost lost a perfectly good Mac's ability to use iCloud/App Store to this issue! And with no serial on the machine (and probably the wrong one/none on the new logic board) Apple had kind of screwed us there. I'm going to rewrite the serial number to the firmware tonight and cross my fingers that it works!
UPDATE Blank Board Serializer did the job. Burned to a CD and booted, entered the correct Serial Number, and now iCloud, App Store etc. all logs in correctly.