I believe you can do that. If you've had the firearm for a while and decided you didn't want it anymore, or need some cash.
I just wouldn't do it a lot.
It becomes illegal if I knew my neighbor had restrictions on buying a firearm himself and asked me to buy it for him. Or if you buy a bunch of guns and sell to people in a state where there are tighter restrictions.
The term straw sale comes in to play:
In the United States, straw purchases are a felony violation of the Gun Control Act of 1968 for both the straw purchaser (who can also be charged with lying on Federal Form 4473) and the ultimate possessor. One of the questions on Form 4473 is “I am the buyer of this firearm” and the purchaser must answer honestly yes or no, by checking the appropriate box in ink. However, purchase of a firearm as a bona fide gift for someone who can legally own such a firearm is permitted.