Easy mistake, and there's a decent chance you can fix it. The PC edition won't work on Xbox, so the goal is a refund on that order, then buying Minecraft from the Xbox store for your friend.
Here's how:
- Go to https://account.microsoft.com/billing/orders and sign in with the account you bought the gift on.
- Find the Minecraft order and click Request a refund. Explain that it was a gift bought for the wrong platform.
- Digital refunds are generally considered within 14 days of purchase, and your chances are much better if the gift code hasn't been redeemed yet. If your friend has already redeemed it, still request it and say so, but it may need a support agent to review.
- If the refund option doesn't show, go to https://support.xbox.com/contact-us and choose Billing and purchases to reach an agent.
One quick question that decides which path you're on: has your friend already redeemed the gift code? If not, ask them to hold off until the refund is sorted.
If this helped, please click Accept Answer so others who gifted the wrong edition can find it.
Reference: https://support.xbox.com/en-US/help/subscriptions-billing/buy-games-apps/refund-orders