Similes of the 'like a' type usually relate some verb with a noun that possesses the property the simile is aiming to convey. For example, 'drink like a fish', 'go over like a lead balloon'. Why 'top', or why 'log' in the related term 'sleep like a log' for that matter?
Tops, or more correctly spinning-tops', were popular amusements in the days before children had access to toys requiring batteries. The British Museum has on display tops from Egypt, dating from around 1250 BC. When a top is spinning well the precessional effect causes its axis to remain stationary and it can appear to be still, i.e. 'sleeping'.
The expression 'sleep like a top' is quite old and is recorded from at least 1693, when it appeared in William Congreve's The Old Batchelour:
"Should he seem to rouse, 'tis but well lashing him, and he will sleep like a Top."
Incidentally, 'sleep like a log' apparently
derives from the sound of sawing being thought to be like the sound of snoring.