The short story on the gift tax: • Gifts that qualify for the $13,000 annual-per-donee exclusion aren’t reportable, whether made to an individual or a charity.
• Outright charitable gifts of cash (including IRA rollovers), regardless of the amount, and property gifts (regardless of the value) qualify for the unlimited gift tax charitable deduction and generally aren’t reportable.
• An outright charitable gift of a partial interest (for example, an undivided one-fifth interest in Greenacre) is reportable.
That use of funds is not an exception to the penalty for early withdrawal.
There are 12 exceptions to the early withdrawal penalty,you can find them all on page 3 of the Instructions for Form 5329, at this link is no exception to the early withdrawal penalty for either a 401k or an IRA for charitable contributions.