Typically the company has a meeting where the payment of dividends is authorized as of a certain date.
then you use a journal entry to move retained earnings to a dividend payable account you create if needed
debit retained earnings, credit dividends payable
when the payment date rolls around you make dividend payments to the shareholders and use that dividends payable account as the expense (reason) for the payment