The NOAA Commissioned Corps descends from the Coast and Geodetic Survey Corps. Before the USA entered WWI, the Coast and Geodetic Survey was a Federal civilian organisation responsible for surveying the USA's coasts and interior. They were needed to do surveying for the war effort in WWI, and the Army and Navy officers normally seconded to the Survey had been withdrawn to do military duties. If civilians were captured on the battlefield doing surveying, they could be shot as spies, so the Coast and Geodetic Survey Corps was organised by commissioning the civilians. And it's stayed a commissioned organisation ever since, although the name has changed, as have the scientific fields they cover.
The USPHS Commissioned Corps descends from the Marine Hospital Service, which was first set up in 1798 to provide medical care to seamen, including naval personnel from 1799. In 1870, it was re-organised as the Marine Hospitals Service, whose first chief was Dr John Maynard Woodworth. He wanted his doctors to be a mobile work force, to be stationed wherever they were needed, and mandated uniforms. As a federal health-care organisation, the MHS' remit expanded in many cases where the federal government needed to provide medical services. Since their hospitals were in major ports, they became responsible for quarantine and other public health functions. In 1912, they became the Public Health Service. Their hospitals began to close after budget cuts during the Nixon administration, and are all gone now. The Commissioned Corps has survived as a public health organisation, and as a provider of medical staff to the other uniformed services.
For both organisations, their advantage is that it's easier to integrate their officers into the larger uniformed services than civilians. This is useful in wartime: essentially, they provide reserves of scientifically trained officers for the military. Other countries use more normal military reserve services, or commission civilians when necessary. The drawback is that the government can't get rid of them so easily as civilian staff, when it wants to.