First, they were weighed at the factory, right before shipment to KSC
Page 9-4 of the Apollo Program Summary Report describes the steps in manufacturing the Command Module:
18.104.22.168 Final operations: In the final phase of command module manufacturing, the vehicle was cycled through another tumble-and-clean operation in which the vehicle was rotated through 360° in each axis to dislodge and remove debris. The weight and center of gravity were then determined, and the vehicle was subjected to an integrated test (sec. 9.1.5). The command module was subsequently moved to the shipping area and prepared for shipment. Such items as crew couches and crew equipment were removed, packed, and shipped separately.
The manufacturing of the Service Module is described on page 9-6:
Following the tests, the vehicle was cycled through the tumble-and-clean positioner to dislodge and remove debris. The cleaned vehicle was then weighed and its center of gravity determined. On completion of these operations, the vehicle was placed in the integrated test stand for the integrated test series described in section 9.1.5. The integrated test completed the manufacturing, test, and checkout operations, and the vehicle was mounted on a shipping pallet and prepared for shipment.
Both operations were performed on a piece of equipment called the "weight and balance fixture":
During flight, ground control estimated the latest weight
As stated by the public affairs officer in the quote below, spacecrafts weights are calculated as the flight progresses, not measured:
PAO: This is Apollo Control; 93 hours, 29 minutes Ground Elapsed Time. Some 5 minutes away from Loss Of Signal on the Apollo 11 on this revolution. A wake-up call is expected from spacecraft communicator Ron Evans here in Mission Control just prior to the time the spacecraft goes into the - goes over the hill on the lunar far side. Standing by as we wait for him to make his call. Presently, Apollo 11 is in an orbit measuring 64 nautical miles [118.5 km] at apocynthion, 55.5 nautical miles [102.8 km] at pericynthion. Present orbital velocity around the Moon, 5,370 feet per second [1,637 m/s]. Spacecraft calculated now to weigh 70,321 pounds [31,897 kg].
Apollo 11, day 5
The weights of the crew, cargo, and propellants were known at launch and added to the vehicle mass. Before each burn, mission control would send the parameters of each burn, including the vehicle's latest estimated weight:
072:51:22 Armstrong: Go ahead.
072:51:24 McCandless: LOI-1, SPS/G&N: 62710, plus 0.98, minus 0.19, GET ignition 075:49:49.65; minus 2889.7, minus 0394.4, minus 0068.6; roll 358, pitch 226, 347; 0169.2, plus 00610; 2917.3, 6:02, 2910.8; sextant star 31, 1066, 358. Remainder of the PAD is NA. GDC align, Vega and Deneb, 243, 183, 012. No ullage. The horizon will be visible just below the upper edge of the hatch window 2 minutes prior to the LOI burn. It will not be visible in the rendezvous window on the left-hand side. LOS at 75 hours, 41 minutes, 23 seconds. AOS at 76:15:29. AOS without the LOI burn, 76:05:30. The values which you would see on Noun 42 prior to LOI burn are HA, plus 431.3; HP, minus 128.2. Read back, over.
072:53:54 Armstrong: Roger. LOI-1, SPS/G&N: 62710, plus 0.98, minus 0.19; 075:49:49.65; minus 2889.7, minus 0394.4, minus 0068.6; 358, 226, 347; 0169.2, plus 0061.0; 2917.3, 6:02, 2910.8; 31, 106.6, 35.8. GDC align, Vega and Deneb, 243, 183, 012. No ullage. Horizon in the hatch window 2 minutes before TIG. AOS with an LOI, 76:15:29; AOS without an LOI, 76:05:30. HA before the burn, 431.3; HP, minus 128.2. Say again LOS time.
The PAD is interpreted as follows:
CSM Weight (Noun 47): 62,710 pounds (28,445 kg).
Apollo 11, day 4
This particular burn was for lunar orbital insertion, which puts the spacecraft on its way to the moon into lunar orbit. This burn is done on the far side of the moon, where there is no radio communication with Earth. Therefore, the parameters were sent about 3 hours before the burn:
PAO: That was Neil Armstrong with the readback of the Lunar Orbit Insertion burn number 1 PAD. The ignition time for that burn; 75 hours, 49 minutes, 49 seconds. That's 2 hours, 57 minutes, 49 seconds from this time. Duration of that burn; 6 minutes, 2 seconds retrograde, and the change in velocity; 2,917.3 feet per second [889.2 m/s]. The expected orbit following that maneuver is 169.2 by 61 nautical miles [313.4 by 113.0 km].
If the LOI fails, they are also given parameters for a trans-Earth injection, to put them back on course to Earth even without radio contact:
073:59:46 McCandless: Roger. TEI-1, SPS/G&N; 38658, minus 0.54, plus 0.65, TIG, 078:02:03.45; plus 2918.0, plus 0377.9, minus 0132.5; roll NA, pitch 041. The balance of the PAD is NA. Ullage; two jets, 19 seconds. TEI-4 PAD, SPS/G&N:, 38658, minus 0.54, plus 0.65, TIG, 084:29:50.59; plus 3137.3, plus 0376.0, minus 0096.8; roll NA, pitch 034. The rest of the PAD is NA. Ullage; two jets, 19 seconds. Both of these PADs are for an undocked maneuver. TEI-plus-4 PAD assumes no LOI-2. Over. Make that TEI-4 PAD assumes no LOI-2.
PAO: That was Buzz Aldrin with the readback of that information which was for contingency Trans-Earth Injection burns if required shortly after Lunar Orbit Insertion. As is normal throughout a flight, Mission Control are ensuring the crew will have enought information to hand in case they lost communications and have to return to Earth themselves. A fuller interpretation of the TEI-1 PAD follows:
(...) CSM Weight (Noun 47): 38,658 pounds (17,535 kg).
Notice how they have calculated the weight for the second burn (less than that of the first burn) before the first burn has even occurred.
After a burn, the vehicle would radio back a burn status report. Mission control would deduct the weight of the propellant and oxidizer used, based on the amounts reported left in the tanks. They double-checked this with the amount that should have been used by the time of the burn.
076:13:23 Cernan (onboard): I've got 39 percent.
[The propellant quantities were recorded at LOI cut-off for Cernan to read to MCC-H as part of the burn status report. The figures recorded were fuel 37.7 percent, oxidizer 39.5 percent. MCC-H need to know this to calculate the spacecraft weight and assess the propellant margins for the remainder of the mission.]
Apollo 10, day 4
Some things were dumped overboard (e.g. urine); their weight was estimated. The lunar module had the advantage of a working scale on board. Prior to liftoff, some materials were carefully weighed, placed in a jettison bag, and discarded from the vehicle. They even weighed the residual water in the portable life support systems and then dumped it!
Sometimes mission control sent fudged values. For example, Apollo 15 was given an even 30000 pound weight for one maneuver, in hopes that it would reduce RCS propellant use:
142:10:03 Henize: Okay, Al - we're finding out that the - tight deadband in P20 is using a little more RCS propellant than we'd anticipated. Nothing's critical yet, but we would like to take - some preventive measures here. And we suggest that you go into the DAP - and load in a CSM weight of 30000, thirty thousand. And before you erase the current LM weight recorded [corrects himself] the current CSM weight, record it for future use. We think that'll cut down the thruster firing a bit.
Apollo 15, day 7
It didn't help.
Finally, the astronauts entered the weight into the guidance computer using Noun 47
The CSM and LEM each had the same model of guidance computer. Programs P12 and P30 required the mass of the vehicle to be input using Noun 47 Verb 21. Program P12 also required the mass of the other vehicle to be entered using Noun 47 Verb 22.