Short answer: it depends. Generally, secretly purchasing a gun on someone else's behalf from a gun dealer, called a straw purchase, is illegal. If the end recipient is not disclosed to the gun dealer/seller, they cannot run the background check for the actual purchaser/owner.