Believe it or not, they date back to the early 1800s and the https://en.wikipedia.org/wiki/Jacquard_machine for weaving cloth. They became used for computing in the late 1800s, notably for the 1890 census with https://www.census.gov/history/www/innovations/technology/th....
The inventor of that, https://en.wikipedia.org/wiki/Herman_Hollerith, founded one of four companies that became CTR, which was later named IBM.
When electronic stored computers became a thing, IBM naturally moved from mechanical computing with punch cards to using electronic computing with data and programs off of punch cards.
We like thinking of computing having started with electronic computers. It really didn't. Punch cards were the last relic of a history of mechanical computing that predated transistors, electronic computers, and even the vacuum tubes that electronic computers were first built from!