This goes back at least to the Greeks. See the first few pages of the Introduction to:
Geometry of Four Dimensions by Henry Parker Manning (1914).
(ADDED 4 DAYS LATER) Danu requested that I expand my answer, so this morning I looked around my things and found the following papers. I've included relevant excerpts from all of them except for Cajori [3], which I know I have a copy of somewhere but was not able to locate. However, I did find Cajori [4] (a conference abstract), which is for a talk Cajori gave on [3] (most likely after [3] had been written and submitted). If I happen to come across [3] at some future time, I'll come back here and include some excerpts from it.
The single best source I managed to find is the Introduction to Henry Parker Manning's 1914 book. Because that book is freely available on the internet (and quite well known), and the Introduction is rather lengthy and detailed, I decided to not include excerpts from it.
1 Raymond Clare Archibald, Time as a fourth dimension, Bulletin of the American Mathematical Society 20 #8 (May 1914), 409-412.
(first paragraph of the paper, on p. 409) [8 of 8 footnotes omitted] WHO first conceived the idea of time as a fourth dimension? In view of the recent development of the theory of relativity the answer to this question is of some interest to both mathematician and physicist. With the definite formulation of our ideas concerning space of $n$ dimensions during the latter part of the last century the conception occurred, doubtless, to many people. But, so far as I am aware, writers who discuss the subject have invariably given the credit to Lagrange (1736-1813), and have referred to a paragraph in either the $\text{first*}$ (1797, Loria† and Enriques‡) or second§ (1813, Dühring‖ and Sommerville¶) editions of his Théorie des Fonctions analytiques.$\text{*}$ This paragraph, the first of the section "Application de la théorie des fonctions à la mécanique," is as follows:†† [a passage in French follows]
(from pp. 410-411) [8 of 10 footnotes omitted] No further elaboration of this idea occurs in the published writings of Lagrange. Apparently independent of earlier suggestion, a writer in Nature$\text{*}$ developed the idea of "time-space." [footnote: $\text{*}$March 26, 1885, vol. 31, p. 481; "Four-dimensional space," by "S."] A decade later the popular English novelist Herbert George Wells wrote a serial, for W. E. Henley's New Review,† in which an invention for negotiating similar "space" is basic. [footnote: †Jan.-June, 1895, vol. 12; "The time machine," republished in book form, London, 1895.] Then came the important mathematical developments by R. Mehmke,‡ A. Einstein,§ H. Minkowski,‖ M. Abraham,¶ A. Sommerfeld,$\text{*}$ Wilson and Lewis,†† to mention only a few names.‡‡ But the main purpose of this note is to make a very small contribution to the history of geometry by way of answer to the question with which this paper commences. Long before the publication of the Fonctions analytiques, indeed as far back as 1754, d'Alembert (1717--1783) published the article "Dimension" in the famous Encyclopédie edited by Diderot and himself.§§ Here the idea of fourth dimension is dwelt upon more at length than by Lagrange, and d'Alembert attributes the conception of time as a fourth dimension to "un homme d'esprit de ma connaisance." It seems questionable that Lagrange, a youth of 18 years [in 1754], was characterized in this way, even though he was in the following year appointed professor of mathematics in the Artillery School at Turin. But at least credit given Lagrange in this connection must, in the future, be rendered with small show of authority. To give appropriate setting to what d'Alembert writes, I quote somewhat fully* from his article in question: [the rest of Archibald's paper consists of a lengthy quote in French]
[2] Henry Parker Manning, Geometry of four dimensions, Topics for Club Programs column, American Mathematical Monthly 25 #7 (September 1918), 316-320.
(from p. 317) [the references to "Geometry" are to Manning's 1915 book Geometry of Four Dimensions] 1. The history of the idea of a fourth dimension. It will be convenient to think of three periods: down to 1827, from 1827 to 1870, from 1870 to the present day. In the writings of Aristotle (384-322 B.C.), Pappus (end of the third century), and, according to Simplicius (sixth century A.D.), of Ptolemy (about 150 A.D.) there are speculations about the number of dimensions of space and the possibility or impossibility of there being more than three. The same matter is referred to by the English philosopher Henry Moore (1614-1687), and by Kant (1724-1813).$^2$ [footnote: $^2$Pappus, after speaking of the three-line and four-line locus (see Heath's Apollonius, Cambridge, 1896, Introduction, chap. v) says that we cannot say of more than six lines, "the ratio of the content of four to that which is contained by the rest, since there is nothing contained by more than three distances. Men a little before our time have allowed themselves to interpret such things, signifying nothing at all comprehensible, speaking of the product of that which is contained by such lines into the square of this or the content of those. These things might, however, be stated and shown generally by means of compound ratios"--Hultsch ed., Vol. II, Berlin, 1877, p. 680. For other references see Geometry, pp. 1-3.] In the development of algebra, which at first ascribed a geometrical meaning to all of its terms, there came about a reluctant extension of these terms beyond those which describe figures of two and three dimensions.$^3$ [footnote: $^3$ Geometry, pp. 2-3.] Finally, there is a suggestion by d'Alembert (1717-1783), and after him by Lagrange (1736-1813), that time might be regarded as the fourth dimension.$^4$ [footnote: $^4$ Geometry, p. 4; R. C. Archibald, "Time as a Fourth Dimension," Bulletin of the American Mathematical Society, Vol. 20, 1914, p. 409.]
[3] Florian Cajori, Early «proofs» of the impossibility of a fourth dimension, [Archeion] Archivio di Storia della Scienza 7 #1-2 (March-June 1926), 25-28.
[4] Florian Cajori, Early "proofs" of the impossibility of a fourth dimension of space (conference abstract #1), Bulletin of the American Mathematical Society 32 #3 (May-June 1926), 212.
Abstract of a talk given at the 48th regular meeting of the San Francisco Section of the AMS, Stanford University, 3 April 1926. The published abstract follows.
The author cites early proofs of the impossibility of four-space given by Ptolemy, Clavius, Leibniz, Kant, Mellin and Whewell. Of these the Clavius-Mellin proof was the only one elaborated by the authors in detail; it was based upon theorems in Euclid's Elements, but one of those theorems was given a generality not contemplated by Euclid.
[5] Florian Cajori, Origins of fourth dimension concepts, American Mathematical Monthly 33 #8 (October 1926), 397-406.
(first paragraph of the paper, on pp. 397-398) Inquiries into the possibility of a fourth dimension of space reach as far back as Greek philosophy. Nevertheless, for 2000 years no one dared to proclaim the existence of such a space. Thus Aristotle in his Heaven says that a solid has magnitude "in three ways and beyond these there is no other magnitude because the three are all." This is the record of man's observation and every-day experience in our physical universe. In his Metaphysics [1066b32] he speaks of a body as "that which has dimension every way"; in his Physics [IV, 1] when considering motion, he regards "dimensions" as six, dividing each of the three into two opposites, "up and down, before and behind, right and left," these terms being taken relatively. More pretentious was the procedure of Ptolemy who was an astronomer, but dealt also with the philosophy of mathematics. He was the first to offer a "proof" of the unprovable "parallel-postulate" of Euclid. In the same way he "disproved" the possibility of more than three dimensions, because, as Simplicius tells us, "it is possible to take only three lines that are mutually perpendicular, two by which the plane is defined and a third measuring depth."$^1$ [footnote: $^1$Simplicii in Aristotelis De Coelo Commentaria, ed. Heiberg, Berlin, 1904, 7a, 33.] The book containing Ptolemy's proof is now lost. Perhaps the first to approach the fourth dimension from the side of physics, was the Frenchman, Nicole Oresme,$^2$ of the fourteenth century. [footnote: $^2$P. Duhem, Études sur Léonard de Vinci, III$^{\text e}$ série, Paris, 1913, p. 388; H. Wieleitner, Isis, vol. 7, 1925, pp. 487, 488.] In a manuscript treatise, he sought a graphic representation of the Aristotelian forms, such as heat, velocity, sweetness, by laying down a line as a basis designated longitudo, and taking one of the forms to be represented by lines (straight or circular) perpendicular to this either as a latitudo or an altitudo. The form was thus represented graphically by a surface. Oresme extended this process by taking a surface as the basis which, together with the latitudo, formed a solid. Proceeding still further, he took a solid as a basis and upon each point of this solid he entered the increment. He saw that this process demanded a fourth dimension which he rejected; he overcame the difficulty by dividing the solid into numberless planes and treating each plane in the same manner as the plane above, thereby obtaining an infinite number of solids which reached over each other. He uses the phrase "fourth dimension" ($4^{\text {am}}$ dimensionem).
[6] Gerald James Whitrow, Why physical space has three dimensions, British Journal for the Philosophy of Science 6 #21 (May 1955), 13-31.
(1st paragraph of the paper, on p. 13) [this is a quote from an English translation of a work by Galileo] And the first step of the Peripatetick argument is that, where Aristotle proveth the integrity and perfection of the World, telling us, that it is not a simple line, nor a bare superficies, but a body adorned with Longitude, Latitude and Profundity; and because there are no more dimensions but these three; the World having them, hath all, and having all, is to be concluded perfect. And again, that by simple length, that magnitude is constituted, which is called a line, to which adding breadth, there is formed a Superficies, and yet further adding the altitude or profundity, there results the Body, and after these three dimensions there is no passing farther, so that in these three the integrity, and to so speak, totality is terminated, which I might but with justice have required Aristotle to have proved to me by necessary consequences, the rather in regard he was able to do it very plainly and speedily.
(2nd paragraph of the paper, on p. 13) GALILEO's first dialogue on the Two Principal Systems of the World opens with this query raised by Salvitatus$^1$ concerning the three-dimensional nature of the physical universe. [footnote: $^1$T. Salusbury, Mathematical Collections and Translations, I, London, 1661, p. 2 sq.] Although the dialogue was ostensibly a debate on the rival merits of the Copernican and Ptolemaic world-systems, Galileo was attacking the philosophy and cosmology of Aristotle and the Aristotelians. Aristotle's De Caelo begins with a discussion of the dimensions of spatial objects and of the world, and it was no coincidence that Galileo's polemic is first directed to the same subject.