I do not have any solid evidence documenting the origin of using turnout as a noun with regard to elections or attendance. But I think it would be reasonable to assume it derives from the phrasal verb to turn out.
That verb's use dates to at least the very early 17th century.
A 1674 publication of Shakespeare's The Tempest, written circa 1611, has the following:
Trincalo: Turn out, turn out all hands to Capstorm.
You dogs, is this a time to sleep?
Heave together Lads.
In Google Books searches, the vast majority of uses of to turn out in the 18th and early 19th century are transitive, with a meaning equivalent to what we today might put as to throw out, typically from someone's home, but sometimes even from elected office.
The earliest use I have found of to turn out as an intransitive verb with the meaning of people assembling for some event is from a letter written in 1771 (published in a book in 1777):
His cortege consisted of two fine gilt coaches ... passing through the town the people all turned out of their houses, and the streets were extremely crowded in order to receive his benediction, which he bestowed on them by stretching out his hand.
Letters from Italy: Describing the Manners, Customs, Antiquities, Paintings, etc of that Country Vol II, p9.
From the 1790s through the early 19th century, there are a number of intransitive uses of to turn out relating to military actions or fighting. For example:
Much abuse had been thrown out against the planters on the score of their cruely, etc but the strongest proof, in his opinion, of the falsehood of these accusations was, the alacrity with which the slaves turned out in defense of their masters and their property against the French.
The Parliamentary Register, or History of the Proceedings and Debates of the House of Commons, Vol 64, 1796, p 294
From the noise we made, the Coomb guard turned out and fired upon us.
transcript from the Trial of Edward Kearney for High Treason (1803), in Cobbett's Complete Collection of State Trials and Proceedings for High Treason, Vol 28?, published 1820, p 709
No people ever turned out more generally, or with more alacrity, that the men of Georgia.
An Impartial and Correct History of the War between the United States of America and Great Britain, published 1815, p 279
...this was of course done by Major J., and Col. H. consequently deferred all further arrangements for the attack, when early the following morning, matters being settled, the garrison, to the amount of about 120, turned out and grounded their arms.
Summary of the Mahratta and Pindar Campaign, during 1817, 1818, and 1819, under the Direction of the Marquis of Hastings, published 1820, p 245
On the 15th, about twelve o'clock at night, we turned out, and at two in the morning marched from the city of Brussels to meet the enemy....
The Life and Campaigns of Napoleon Bonaparte, from His Birth down to His Departure for St. Helena, published 1815 p 49
By the late 1830s, turn out was being used intransitively to describe non-military gatherings.
As soon as that matter was settled, the whole body of negroes turned out cheerfully, without a moment's cavil.
Emancipation in the West Indies: A Six Months' Tour in Antigua, Barbados, and Jamaica in the Year 1837, p 118
In Trenton, a band of aged matrons turned out to welcome and thank him [George Washington] for his defence of their property....
Notes on the United States of America during a Phrenological Visit in 1838-39-40, published 1841, p 258
It probably is not much of a leap to go from there to turning out to cast a vote, or being turned out to cast a vote, and then onto describing the participation in the voting using turnout as a noun.
More than two hundred sailors, from United States' vessels of war, brought over to the city to vote--sloops and small craft, trading down the north and east rivers, each known never to have more than three hands, turning out thirty or forty voters from each vessel.
Second Series of Diary in America with Remarks on its Institutions by Capt C.B. Marryat, 1840, p 173