If God did not exist, it would be
necessary to invent him
Voltaire's statement was made as part of his larger argument that the existence of God and/or belief in God
are beneficial and necessary for civilized society to function.
The larger context of the debate in which he was engaged at the time
indicates that he did not intend this statement to be an ironic quip
essentially claiming that God is fictional, as it is commonly used
In fact, the statement was made as part of a piece that he wrote
comdemning and refuting an atheistic essay called "The Three Imposters".