The purpose of a Y valve in a marine sanitation device is to select where the effluent is going. There are several styles and configurations and there may be more than one on the boat. One setting will discharge the effluent out the hull directly into the sea. The other setting will send it from the holding tank for pump out to an on-shore sewage facility. The y valve has a locking feature that must be secured in port to prevent accidental discharge into the prohibited are. Some local and national laws prohibit pumping in No Discharge Zones (NDZs) and it is the boaters responsibility to know where those are. Discharging overboard is generally outlawed within a minimum of 2 miles of any port in US waters. NDZs can extend to entire bays and ecological zones. When in port or a NDZs a padlock or seal on the valve to the sea discharge position is required to be put on the Y valve. Hefty fines can be levied for unsecured Y valves. A recommended practice is when out at sea make a note of your position in the log book before emptying the holding tank into the sea. Forget About It For Boats in the holding tank would be beneficial to the environment, but it is still illegal to pump in a NDZs.
For USA NDZ see https://www.epa.gov/vessels-marinas-and-ports/vessel-sewage-discharges-no-discharge-zones-ndzs