To answer super-literally:
- is it possible to get a specific medal in a specific sport just by spending enough money? No.
- does every person (and their country) who wins a medal spend a large amount of money for that purpose? No.
Look at wins by Singapore, Fiji, or other small countries. They spend less dollars per capita and occasionally win more medals per capita. There is a certain amount of luck, genetics, and such at play.
But in general, over decades, will spending a lot of money building infrastructure (arenas, tracks, training facilities), paying coaches, giving athletes living stipends so they don't need "Day jobs" and can train all day, and running TV ads saying that it's great to be an Olympic athlete all result in more Olympic athletes and better performances from those athletes? Of course it will. That's why countries do it.
Is it mainly a question of money? It depends on the sport. In Athletics, probably yes. That's a glamour sport that countries want to be known for. In sailing or judo or fencing, probably less so. The thing is, getting amazingly good at something takes a lot of time, equipment, coaches, medical help (physiotherapy, sports psychology, etc), buildings, transportation to events, plane tickets and hotels to international events, you name it. The days when athletes were rich people who could fund all that themselves are long gone. The teams where all the athletes have jobs almost never beat the teams where the athletes do nothing but train and compete. That's why, when someone does, we make a big deal of it.