Archaeologists' methods for determining the age of things fall into two categories: In relative dating, we use an object's association with other objects as a reference. So if you find some pottery on the floor of a buried Roman villa, you can be pretty sure it's from the Roman period too.
Then if you find pottery in the same style in say, a pit, you can now date the pit itself to the Roman period too. Obviously this is not the most precise method, but over the years archaeologists have used this principle to create such an extensive "database" of artefact types that they could give you a ballpark age of pretty much anything.
So despite great advances in scientific dating, the vast majority of finds are still dated using good old fashioned relative methods. Absolute dating exploits a variety of physical processes that we know happen at a predictable rate, usually some form of radioactive decay. The most well known example is radiocarbon dating. The carbon dioxide in our atmosphere contains a small amount of carbon, a radioactive isotope.
When they're alive, organisms are constantly swapping carbon with the atmosphere so they have the same proportion of 14C in their cells. But when they die they stop swapping, and the 14C decays into bog standard 12C nitrogen at a known rate thanks for the correction.
So by ascertaining the amount of 14C left in a sample of organic material from an archaeological site, we can determine how old it is with a good amount of precision. In addition to radiocarbon dating there are a number of other absolute dating methods that use the same principle with different radioactive isotopes, as well as methods that use other physical processes that happen at a fixed, known rate.
With any of them, the key to using them successfully in an archaeological investigation is context. We rarely get to directly date the thing we actually want to know the age of, like a house or a tool. Instead we'd date say, some seeds on the floor of the house or a bone found in the same pit as a tool.
It becomes crucial to be absolutely sure that your sample is contemporaneous with the thing you actually want to date, that you understand how it got there and you can rule out "contamination" by, for example, seeds blowing into a house that had been abandoned thousands of years earlier.
As you might have guessed cave paintings and prehistoric art in general poses a problem for both approaches, namely that it's just sitting there in the side of a rock and has no context to speak off. The only thing you can possibly directly date is the pigment itself, which for a very long time precluded the use of absolute dating because there simply wasn't enough of it but more on that later. As a result we're still mostly reliant on relative dating, and crude relative dating at that.
For example, say in one cave with paintings there is also evidence that people lived there, and this can be dated using conventional methods. You could infer the paintings were made by the people who lived there and are therefore roughly the same date. And then you find paintings in the next cave that look similar, and so on. Sometimes you can glean some extra information from the painting itself; it could depict animals which have been extinct in the area since X years ago.
Or from the stratigraphy of the cave; maybe the paintings are buried, or in a section that you know was closed off at a certain date. However obviously none of this gives you a particularly reliable or precise date. Usually it will be something like "Upper Palaeolithic" which was tens of thousands of years long. Using absolute dating can narrow down the age of an associated deposit, but that doesn't give you any more confidence that the painting was really made at the same time. Naturally archaeologists aren't very happy with this and have long sought to apply absolute dating directly to cave paintings, using some quite ingenious methods.
Currently the two most promising are radiocarbon dating pigment and Uranium-Thorium dating. Some pigments used by prehistoric artists were organic-based like charcoal blacks and so in principle can be radiocarbon dated.
Unfortunately there are a lot of obstacles: Nevertheless, sophisticated radiocarbon techniques can occasionally overcome these problems. A more recent approach is to look not at the pigments but at little calcite concretions that sometimes form on top of cave paintings, like mini stalagmites.
Fortuitously, these contain small amounts of radioactive uranium, which decays into thorium and can therefore be used for radiometric dating. Again, the very small samples are a challenge and you have to bear in mind that this dates the calcite not the painting itself, but when successful it tells you the latest date a painting could have been made because obviously it was already there when the calcite started to form on top of it.
Recently this method has been used to push back the date of the oldest cave art to at least 40, years ago, which is quite a bit older than we had previously concluded from relative and radiocarbon dating. As an aside, you asked about cave paintings, which are obviously the most striking examples of prehistoric art, but it's actually far more common to find rock carvings or petroglyphs.
These present even more challenges when it comes to dating, because there's no pigment, no calcite, probably no associated living deposits and they've usually been completely exposed to the elements for millennia. If you're lucky you can find one buried, and use the age of the deposit covering it or thermoluminescence dating which dates when it was last exposed to light to determine when, or be very clever with the local geology.
But most of the time they're anyone's guess.