Securities pay dividends at regular intervals determined by the issuer. It is usually monthly, quarterly, every 6 months or annually.
Even if you sell the security before the next payment is due, the dividend is still calculated and paid out by the issuer on the next scheduled regular date. You will receive an amount adjusted to how long you were invested in the security in that period.
Even if your portfolio and/or account were closed, you will continue to receive due dividends directly to your nominated bank account whenever the issuer pays them out.