It is because of oxalic acid.
Green unripe tomato has more oxalic acid. So it tastes more sour.
Red tomato has less oxalic acid.
Why tomato has oxalic acid ?
It is a natural protection.
Acid stops insects from eating it.
People with kidney stone are told not to eat too much tomato.
It can make kidney stones.
Oxalic acid + Calcium = Calcium oxalate = kidney stone