It seems like all big social media sites and dating apps prohibit users from uploading photos containing nudity. Is there a legal motivation for that?
As I understand them, most social media companies' policies do not actually prohibt nudity.
Twitter, for example, does not prohibit nudity, but it does prohibit "media that is pornographic or intended to cause sexual arousal." Facebook, for example, allows nudity where the user clearly intends to share it "as a form of protest, to raise awareness about a cause, or for educational or medical reasons."
Facebook explicitly says that its policy is designed to "prevent the sharing of non-consensual or underage content." Under 18 USC 2252A, it is a felony to knowingly receive or distribute child pornography. It would probably be hard to prove that Facebook knew about most pornography, but I can imagine a prosecutor arguing that it should be liable for any distribution between the time someone first flagged the content and the time Facebook deleted it.
So providing adults with pictures of nude children is a problem, but there's also a liability concern going in the other direction, as 18 USC 1470 also makes it a felony to transmit obscene material to anyone under 16 years old, which would probably include something like 5 percent of Facebook's users.
Reason #1: They are private companies and they set their own terms of service for their users, for general user comfort, ethical or business model reasons. The terms of service users agree to when using such services are legally binding contracts, and that contractual relationship can give each service the power to remove nudity (and user accounts) if their TOS forbids it. Private companies are not generally bound by the First Amendment; see Freedom of speech in the United States (Wikipedia).
Reason #2: They wish to protect themselves (and their users') from legal liabilities due to users distributing materials that fall under the legal standard of child pornography (Wikipedia) or depict other illegal activities. Most platforms are protected by Section 230 of the CDA; see Section 230 Protections | Electronic Frontier Foundation, but there are exceptions: Backpage - (Wikipedia).