The upper one is a cloth skull cap, a non-regulation headwear for Navy men. Here is a Union seaman wearing one on deck:
the regulation uniform from 1852 called for the wear of sennit straw hats, with or without black covers, and ribbons in muster dress. While at sea the men could wear thick blue cloth caps without visors.
During the war years, a large proportion of vessels evidently did not bother with the regulation uniform hats (white straw, worn with black "tarpaulin" covers in winter, which in the pre-war years the seamen themselves wove, covered, painted etc.) at all, but made up fancy "muster" versions of the cloth cap, usually with the ship's name marked on a silk ribbon etc. Alva Hunter of the Monitor
Nahant, mentions mid-war having such a cap with his ship's name on it, as well as an "everyday cap" with no markings.
For example, here is George Geer of the USS Monitor, in a cap suitable for "muster"
Here are his shipmates on deck in the summer of 1862, in their regulation "everyday" caps.
While doing without the regulation hats, many crews met their spirit (calling for white or black headgear at the Captain's discretion) by making up white covers for their cloth caps, as worn by the crew of the
Mendota on their fancy muster caps.
From the Uniform Regulations of the Navy revised Jan. 24, 1864, were little different from those of 1852.