It can work out just fine...
But, getting a new dog either a rescue or a puppy - means housetraining, which means multiple trips up and down trying to get out before they go.
For puppies that may be MONTHS and really slow down house training - not everyone lives in a flat where they want to zoom down three flights of stairs in their dressing gown and pyjamas at 3am to stand on a patch of grass waiting for a weewee...
For adult rescues - again that could still be weeks of rushing them out at all hours until they learn and become confident in their new home.
If you have your own garden, you have outside space to play and train that is secure and you control. If your dog has some behaviour issues for example is reactive on the lead (and many many dogs are its probably the most common behavioural issue going) - then a garden is a great place to start behaviour modification.
Most outdoor training issues first start with limiting the environment and working in a place with low distraction that the handler controls - with a flat with no garden you don't have that option, you're effectively starting halfway to the deep end (or right IN the deep end for some dogs).
Trying to address pulling on the lead, reactivity to people or other dogs, fear of people/other dogs/traffic related issues... when you have to come out of the flat front door and work in public can be an absolute nightmare, for some dogs it would be impossible, they would just get worse and worse, and no matter how much skill the trainer had, you can't train in the wrong environment.
So yes its possible for some dogs, dogs with no issues, who are already house trained.
But for those getting a puppy or an adult rescue, I would avoid doing that if you live in an above 1st floor flat and have no garden. There is a strong chance it won't be fun at all.