Why do miners choose low fee rate transactions sometimes? Miners prefer high fee rate transactions to low fee rate ones, but the part which I don't understand is why miners pick a low fee rate transaction that has been waiting for hours in the mempool into their blocks, while they can find higher fee rate transactions in the mempool.
Is this some kind of moral thing to help those transactions to get confirmed or what?
For miners lower transaction fee doesn't matters but fee rate does.
There are three cases where the miner chooses transactions with low fee rates.

1) When the mempool has three sets of transactions {A}:High fee rate , {B}:Average fee rate and {C}:Low fee rate. If there are few transactions of set A and B the miner will select transactions from C as well.

2) In a child-pay-for-parent scenario, where A is the parent transaction and B is the child transaction.

A: { size: 200 vB, fee: 200 satoshi } ⇒ fee rate: 1 sats/vB
B: { size: 100 vB, fee: 2800 satoshi } ⇒ fee rate: 28 sats/vB


The miner really wants to collect the fee of B, but B spends an output of A, and the miner has to add both A and B in order to get the transaction fee.
You can see this in full detail here.

3) The miner has some personal interest to add a certain lower fee rate transaction.

Hope it helps.