Assuming that your plan allows for withdrawals at all, which not all do, it would be legal to take a hardship withdrawal to pay the medical bills. Not the credit card debt.
If your plan allows for loans, you could take a loan from the plan for the credit card debt, but the loan would have to be paid back with interest.
The court also does not control the above. You can decide to do that on your own.
There is another option. You can agree to divide the 401k as a marital asset, (she would normally be entitled to 50% of whatever accrued during your marriage and that would involve the court) however you feel is fair, taking those debts into consideration. She could then roll her share into an IRA of her own, and then withdraw from the IRA whatever she needs to cover the bills. Please note however that taxes will have to be paid on whatever is withdrawn, so she would have to make sure that enough money was withheld to fully cover the taxes. She should consult a tax professional to figure out how much withholding she will need. Luckily she would be able to exclude the 10k of medical bills from the 10% penalty (but not from regular tax) so that will help the tax bill.
Now, just so that you know, any debts that accrued during the marriage and any assets that accrued during the marriage are normally divided 50/50. If her debts accrued during the marriage it might actually be financially more beneficial for you to take a loan to cover all of it, and offset her half somewhere else. Yes, you would have to pay back the loan but it would be far less expensive in the short term and could be less expensive in the long term, than paying the tax on a withdrawal.
So, basically you both have some research to do. You need to find out what your employer's plan allows in terms of hardship loans and withdrawals, and you both need to figure out what the tax ramifications would be of withdrawing. You also need to figure out how your marital assets/debts should be divided under the law, and what is the most cost effective way of dividing them. Many divorcing couples neglect to take tax into consideration when dividing assets and debts.