Why did the weight of the submarine, or trim, change?
The weight of any ship changed as it was operating. Fuel was used, food was eaten, supplies were used and ammunition was expended. All of that made the ship lighter. Resupplying, in port or at sea, replaced some or most of that weight. The weight of submarines also changed for those same reasons.
However, submarines were different in a few important ways. The most important difference was that the weight of the boat mattered much more. If a cruiser got much lighter, it might just ride higher and more efficiently. If a submarine got lighter, it might have had problems submerging quickly or staying submerged. The boat needed to take on some water to offset the weight loss.
NOTE: Surface ships could have problems if they got too light. They might have had problems riding out a big storm unless they took on some ballast water for stability.
Another difference is that submarines actually got heavier as they burned fuel. That was because the fuel was stored outside of the pressure hull. The fuel tanks were among the ballast tanks. In order to keep the fuel tanks from collapsing due to pressure, sea water was fed into the tank below the fuel. This way, the fuel was stored at sea pressure even when submerged. Sea water weighs about 1.5 pounds more per gallon than diesel fuel. This was very helpful in that the weight gained by burning fuel helped offset the weight loss from other changes.
A third difference is that the salinity of the water also mattered much more to submarines. If the water was less dense, as for example near the mouth of a river, the submarine weighed the same but appeared to be heavier. Again, the same thing happened to surface ships but didn’t usually matter as much.