Normally once funds are in Apple Account balance the only way to get them out again is to spend them. Some possible exceptions are described below.
1) Laws requiring gift card balance refunds.
From: Check your Apple ID balance - Check your Apple Account balance - Apple Support ➔
"About unused Apple ID balance
You can't redeem or return Apple Gift Cards, App Store & iTunes Gift Cards, or unused Apple Account balance for cash, except as required by law. If your jurisdiction allows for refund of redeemed gift balances, you can contact Apple Support." Read the support article for more details.
The above excerpt only mentions balances from gift cards as being eligible for refunding, and only in limited places where laws may require that. Read the support article for more details.
2) You are deleting an Apple Account.
How to delete your Apple Account - Apple Support
“What happens to my App Store or iTunes Store credit when I delete my account?
Any unused credit balance in your account isn't redeemable or refundable after your Apple ID has been deleted. You can either spend your balance or contact Apple Support to request a refund before deleting your account. Similarly, if you have a balance due to Apple, you must clear this balance before we can delete your account.”
3) There are posts (e.g., Accidentally added funds to Apple ID rath… - Apple Community ) claiming that if funds were transferred from Apple Cash or a bank account, Apple might grant a reversal request to the originating account. This is not mentioned in Apple’s documentation (which, if anything, pretty firmly states the opposite about no “return” of funds), so even if Apple might do this on occasion, they are not so obligated. If you wish to speak with Apple, click here ➔ Choose your country or region - Official Apple Support Select your country, then a product. If you don't see one that handles your issue then keep experimenting with selections until you reach one that gets you a chat session or a telephone call and get the representative to redirect you. This page has telephone numbers for contacting Apple for support and service ➔ Contact Apple for support and service - Apple Support Do not use the standard refund request service. You are asking for a special service and need to speak with a live representative.