Yes, it's prohibited at the federal level, but the state laws on that vary, and the states are generally the ones doing the enforcement. An example, in Mississippi (
http://billstatus.ls.state.ms.us/documents/2022/pdf/SB/2001-...):
> A registered qualifying patient or registered designated
caregiver shall not be denied the right to own, purchase or
possess a firearm, firearm accessory or ammunition based solely on his or her status as a registered qualifying patient or registered designated caregiver. No state or local agency, municipal or county governing authority shall restrict, revoke, suspend or otherwise infringe upon the right of a person to own, purchase or possess a firearm, firearm accessory or ammunition or any related firearms license or certification based solely on his or her status as a registered qualifying patient or registered designated caregiver.
Edit: By enforcement, I mean that it's not going to be the FBI or the ATF that knocks on your door if it's discovered you have purchased a firearm with a medical marijuana card but the state, county, or municipal police. The feds might go after the store, though.