The short answer, explained
Company law only allows a dividend when the company has enough distributable profit to cover it, based on relevant accounts. If it doesn't, the dividend is unlawful, no matter how it was documented.
HMRC doesn't police company law directly, but it does police the tax consequences. If your dividend wasn't lawfully paid, HMRC will typically say it wasn't a dividend at all for tax purposes.
Instead, HMRC recharacterises the payment, most often as a director's loan, sometimes as employment income. Either route usually means more tax than the dividend rates you originally applied.

