I am wondering what are good examples of substances that were initially thought to be elements but then were found out to be compounds. How exactly were these substances found to be compounds?
"Are there substances that were initially thought to be elements but are actually compounds?"
Good candidates for "substances initially thought to be elements but actually compounds" arguably are some of the substances classed by the phlogiston theory as "calx". The calces included substances now known as metallic oxides. According to modern chemical evidence these are certainly compounds. But as seen by Georg Ernst Stahl (1660-1734), proposer of the phlogiston theory (building on ideas of his predecessor Joann Joachim Becher, 1635-c.1682-5), metals were composed of calx and phlogiston. (See [https://www.britannica.com/science/phlogiston].) The phlogiston theory gave a view about processes such as combustion and rusting that was nearly the opposite of later and modern theories. It saw such processes not as a combination with oxygen (then still-undiscovered), but as something involving the escape of phlogiston.
Combustible materials, including charcoal, were supposedly rich in phlogiston: so charcoal-smelting, e.g. of iron or copper ores or oxides, was supposed by the phlogiston theory to combine the calx with phlogiston to compose and yield the metal.
It does not appear that the phlogistonists thought that a calx could itself be decomposed into anything more elementary. Their idea that a calx could be formed by the escape of phlogiston -- from a supposedly compound material such as a metal -- shows that they regarded the calx as in some sense more elementary than the metal. It may be difficult to find a specific statement that the calx, as conceived by the phlogistonists, was an (absolutely) elementary substance.
But from the mid-1600s to later 1700s the concept of element underwent evolution away from more ancient ideas. Already in 1661 Robert Boyle gave in "The Sceptical Chymist", London, 1661 (in part 6) a definition of an element that approaches the modern idea:
"And to prevent mistakes, I must advertize You, that I now mean by Elements, as those Chymists that speak plainest do by their Principles, certain Primitive and Simple, or perfectly unmingled bodies; which not being made of any other bodies, or of one another, are the Ingredients of which all those call'd perfectly mixt Bodies are immediately compounded, and into which they are ultimately resolved. ..."
According to E. J. Dijksterhuis, Boyle's idea gradually gained influence, and "After the appearance of 'The Sceptical Chymist', Aristotle’s doctrine of the four elements as well as Paracelsus’ theory of the three principia gradually passes into disuse." E. J. Dijksterhuis , transl. C. Dikshoorn (1961) 'The Mechanization of the World Picture', Oxford UP : at 435.
Boyle did not commit himself to state which substances ('bodies') he regarded as qualifying to be Elements under his definition. But from the indications outlined above, it seems clear that as between the calx (i.e. oxide, now recognized as a compound) of a metal (now recognized as an element) and the metal itself, the calx was regarded on the contrary by the phlogistonists as the more elementary component, out of which the metal, clearly in their view a compound, was composed by the addition of phlogiston.
Arguably, therefore, the phlogistonists' view of the calx, now recognized as certainly a compound, may well qualify as an instance of the modern idea of element as well as of the idea of 'Element' proposed by Boyle.
After the discovery of oxygen in the 1770s, the facts about combustion and rusting etc. were reinterpreted, so that metals were then clearly seen to be at least more elementary than their oxides. I have not seen any contemporary considerations, whether theoretical or experimental, of the question whether the metals were only relatively more elementary, or absolutely elementary. Lavoisier in 1789 included the metals as elements in his new table (https://www.rsc.org/periodic-table/history/about), but it seems possible that the evidence on which he classed the metals as elements might not have been exhaustive of the possibility that they or some of them might be further decomposed.