The origin of the supposed quote is somewhat older than the 1958 date mentioned in another answer.
On Wednesday 18 October 1950 Clarence E. Manion, Dean of Notre Dame Law School, gave a speech titled "Key to Peace" as published beginning on page 21 of the November issue of the Cleveland Bar Association Journal (volume 22). In the speech Manion said:
...one of the most erudite of the Founding Fathers, James Madison, said that "we have staked the whole future of our American Political Institutions upon the capacity of mankind for self government"
This corresponded to the actual Madison quote:
...to rest all our political experiments on the capacity of mankind for self-government...
Over the next 4 years, Manion gave various speeches that were widely published connecting the Madison quote to the Ten Commandments. Some examples of his speeches are below.
03 April 1951 addressing the Pennsylvania General Assembly Manion said (emphasis added):
self government means and was meant to mean, the ability of the individual citizen to govern himself, under the Ten Commandments of God, and that was precisely the type of self government that James Madison had in mind when he said that “We have staked the future of all of our American institutions upon the capacity of mankind for self-
government.”
In a 10 November 1953 speech, published in Addresses and Reports of the American Petroleum Institute, Manion said (emphasis added):
James Madison truly said, that the future of our constitutional system depends on the "capacity of mankind for self-government." That doesn't mean merely voting or politicking. Self-government means self-control, self-restraint, under the moral laws of God. That's where the Ten Commandments come in. Moral self-government under God's commandments is the very predicate of our system of strictly limited civil government.
The same was also published in the Kentucky State Bar Journal and published in the 28 January 1954 Congressional Record.
Then in April 1954 Marion gave a speech titled "Our Spiritual and Moral Resources" which, as published in Proceedings of in of the Eighty-Seventh Convocation of The University of the State of New York said, quoting (emphasis added) from page 274 of the proceedings:
But more than the truth about the supremacy of God and the consequent subordination of government must be learned if our moral and cultural, and in the last analysis, our material resources are not to be exhausted. Not merely the fact of God, my friends, but the fact of God's Commandments, and their consequent obligation of service to God must be taught as an essential complement to our Constitutional system.
In the very beginning of our history James Madison put a very significant statement in writing. Madison said, "We have staked the whole future of our political institutions upon the capacity of mankind for self-government."
A thoughtless future generation has interpreted self-government to mean the democratic process of electing officers and selecting your own public servants. That is not what Madison said. Madison said that the future of our political institutions depended upon the capacity of mankind to govern himself, to control himself, to restrain himself according to the moral laws of God.
The future of our American civilization, in other words, depends upon our continued respect and observance of God's Commandments, which, from the day they were given to us until this, are the best formula for self-government that has ever been written.
So Clarence Manion was responsible for connecting the Ten Commandments to Madison, but without claiming a direct quote by Madison about the commandments. Later, others changed what Manion said such that larger portions were a supposed Madison quote.