An account holder who purchases a US stock outside of normal or regular trading hours (i.e., 9:30 a.m. to 4:00 p.m. Eastern time) but during the extended trading hours session (i.e., 4:00 p.m. to 8:00 p.m. Eastern time) on the day prior to that stock going ex-dividend is entitled to receive that dividend. The reasoning behind this is that trades executed during the extended trading hours session on Day 'T' settle at the same time ('T+2') as trades which are executed during regular trading hours on Day 'T'. All such trades will therefore settle within a timeframe sufficient for the purchaser to be recognized as an owner of the shares prior to the close of the Record Date.
Following the same logic, an account holder who sells and closes out a long US stock position during the extended trading hours session on the day prior to that stock going ex-dividend will not be entitled to receive that dividend. However, if the stock was sold stock (i.e. an opening trade), the account holder would be obligated to pay the dividend to the lender of the shares.