Two reasons. First, physics says it ought to be happening, to some degree or other. Second, the data say it appears to be happening.
Most of the sun’s energy reaches Earth as visible light, around a kilowatt per square meter. Some of this is reflected back into space, especially from ice and snow. Some is absorbed by land and sea, and heats the Earth’s crust.
Any object that is above the temperature of absolute zero radiates energy. The sun is hot enough to radiate visible light. Earth is much cooler, and radiates infrared.
There is an energy balance. A budget, if you will. Energy arrives as visible light (as well as radioactive decay deep underground), and leaves as infrared. The average temperature of the planet rises and falls until the budget is in balance.
Carbon dioxide and methane are transparent to visible light, but not to infrared. Their presence in the atmosphere reduces the energy outgo, but not the energy income. So Earth’s crust and oceans warm until they emit enough infrared to balance the budget.
At least, this is the theory.
But it’s interesting to note another gas that blocks infrared – alcohol vapor. Very small amounts of alcohol in your breath block enough infrared to activate the breathalyzer that gives a cop probable cause to take you in.
So the idea that .04% CO2 in the air acts like a blanket to trap infrared, and thus heat, should not be too hard to swallow. The same effect deprives thousands of the right to drive every year.