Other replies supporting taxing externalities and scarce resources are correct, but it can be generalized as taxing undesirable behavior to disincentivize it.
“Undesirable behavior” is overly broad to the point of being actively misleading, and gets you into sin taxes. smut or drugs are not the scarce resources anybody is talking about here.