I’m checking a couple of solid public-health and environmental sources so I can answer this accurately.
Yes. A lot of medicines can leave the body in urine or feces, either unchanged or as metabolites, and then go into sewage and wastewater. EPA and EMA sources both describe human pharmaceuticals entering wastewater after use and excretion, and note that wastewater treatment does not always remove all of them.