Federally licensed firearm dealers must follow certain procedures before selling people guns. They must, in part, verify the buyer's identity and run a background check, and they can typically sell only to those who show up in person. These procedures are devised to keep guns out of the hands of people who aren't allowed to have them—for example, people with felony convictions or who are addicted to drugs, and those classified as mentally ill. (See Can someone possess a gun after a criminal conviction?) They're also designed to allow authorities to trace guns that are used in crimes.
Congress hasn't heavily regulated the secondary gun market, meaning that federal law generally doesn't stop people from giving guns as gifts and reselling them. (It is, however, a crime for a private party to sell a gun to someone she knows or has reason to believe can't legally possess it. (18 U.S.C. § 922(d).)
Even though people can legally dispose of guns in the secondary market, they can't buy them on behalf of others from federally licensed dealers. It doesn't matter whether the person who will keep the gun is eligible to own it—purchasers who are caught lying in the application process will likely face criminal charges.
Example: A former police officer named Abramski offered to buy a Glock 19 handgun for his uncle, named Alvarez. (Abramski v. U.S., 573 U.S. ___ (2014).) Alvarez could have legally bought the gun himself, but Abramski was supposed to be able to get a discount. So, Alvarez provided Abramski $400, and Abramski purchased the handgun from a federally licensed dealer. When filling out the requisite government form, despite a warning that misrepresentation was a federal offense, Abramski indicated that he was buying the weapon on his own behalf. After the sale was complete, he transferred it to Alvarez. The U.S. Supreme Court upheld Abramski's conviction under federal law that prohibits making false statements and representations in the course of firearm purchases. (18 U.S.C. § § 922(a)(6), 924(a)(1)(A).)