This policy is standard for many US banks, e.g. Wells Fargo and Chase and often applies to all ACH/direct deposits, such as government benefits, pensions, and tax refunds. It is called early funds availability, and it actually is less generous than you expect.
Normal ACH/direct deposit clears overnight on business days. The bank receives a message that money is to be deposited, but the actual fund transfers are netted. (That is, outgoing transfers are paired with incoming transfers and cancel each other out.) This netting process is done in a batch for maximum efficiency, so transactions have to wait until the end of the business day, at which time money actually is moved.
Consistent with this clearing, by law, the bank must make the money available the business day after the business day on which ACH transaction arrives.
(Same-day direct deposit/ACH exists. Basically the same process occurs several times throughout the day. The employer has to be so motivated to elect for it, the bank loses the float on the money and therefore charges the employer more for the service.)
In most cases, therefore the bank advances you money for a matter of hours. Two days early occurs if you are paid on Friday, like many people are, then funds normally become available on Monday, and here the bank makes it available on Friday.
If you use those funds for a delayed clearing transaction, like an outgoing ACH (bill/mortgage payment), check clearing, or debit card purchase, the bank will have the funds in hand before they are sent out again. Only transactions like cash withdrawals and wires will the bank actually have to loan you funds.
The bank loses a little on float (interest) but gains customer loyalty and use of the account as one's default deposit account.