A good middle ground would be to have the company make a donation to the candidate's choice of nonprofit.
How is this enforceable? Even in the case that someone finds out about it, what’s the company going to do? Sue the interviewing company for the rights to a few hours of work?
What are the damages?
As for suing you? Again what are the damages?
It’s almost certain there are no damages assuming you are just working on a take home project not something that they are going to actually use to compete with your employer.
Just because something is in the terms of your contract doesn’t actually mean you really need to worry about a lawsuit.
A company might fire you if they find out, but the chance that they fire you is to small to worry about.
And even if you don’t do take home work for pay, you don’t want your company finding out you are interviewing. Taking a token payment doesn’t change anything practically.
People have contracts with all kinds of stupid things in them. If they aren't practically enforceable, they can safely be ignored. Any company saying they don't pay for take home projects because of employment contracts is just using that as an excuse not to pay.
There are people out their with contracts that say they can't even interview at rival companies, how many companies out there refuse to conduct interviews because of this?
Donating to charity has tax implications for the company too, but they're much simpler.
And for that matter, giving real-but-unpaid work to do as part of an interview may be illegal. So paying for your time may be something companies are doing to protect themselves taxwise, not just for good will.
Now one worries, is this itself a test? Are they judging my desire to donate.
It's kind of like at salary negotiation. You can impress them with how you really are there for your passion not materialism. Or you can get money.
Then I'd be worried... are they watching to see whether I engage in hollow virtue-signalling?