There is a lot of case law surrounding obscenity, and courts have ruled that bans on obscenity do not necessarily violate the first amendment (there are a variety of tests involved). The rationale never seemed sound to me, but somehow I have not been appointed to the Supreme Court.
https://en.wikipedia.org/wiki/United_States_obscenity_law