It is a felony for one person to buy a firearm for another, even if the other person is legal to own/purchase one.
No, it is not. As long as your state has no further prohibitions, you can buy a gun and give it or sell it to another person.
However, this deal COULD become a "straw man" purchase if they try to skirt the rules. If your friend's friend buys the gun legally but then gives it to your friend -- who cannot legally buy it himself in that state -- then it's a straw man purchase and is illegal.
Your friend needs to find an FFL
in his home state who will transfer the gun from the dealer in PA. Just leave the Maryland aspect out of the picture. He can't have it transferred to a dealer in MD and buy it because he's not a resident.
Unless this Glock is going to be practically free, the effort and expense is probably not going to be worth it.
-Sam
P.S. -- Where does this come from?
it might be unlawful for him to drive across certain state lines with that firearm.
Because of the "Safe Passage" passage in GCA '86, you may travel across any state line (even D.C.) on your journey from a state where you can own a gun, to a state where you may own that gun, without breaking the law. Now, IL will require an FIOD card to own that gun, but the dealer who handles the transfer can fill you in on that.