Bulk programming with unique id
You can buy devices that have unique serial numbers in them and connect your MCU to them. Serial EEPROMs that have this feature are available from Microchip  and Amtel.

For pure MCU solutions you would likely have programming software that programs the base image, then a station or step that programs the serial number as provided by an external PC, for example. The PC has software to make sure it increments each time.