It is an instinct to bury their excrement and urine.
They usually learn to use a litter box by watching the mother cat.
I had an injured feral cat that was brought inside after his surgery. He hid upstairs under a bed for 6 months but came downstairs and used the litter box. There was never a problem. (They have a great sense of smell and can find the box easily, once you plant their scent in it.)
I had a pure bred himilayan kitten once from birth, who was taught by Mama Cat, but she refused to use the litter box. Instead peeing in a closet, and pooping in the bathtub. No matter what I tried, it was a failure. Some young girl took the cat off my hands. She must have worked something out, because she kept the cat.
Generally, cats are pretty good about this. Once you get their scent into the box, they can figure it out.
Another cat, who was getting old and ill, started having accidents and not making it into the basement where the box was located. I first put one of those rubbermaid boot racks near the wood stove (where his accidents were taking place), and he started peeing in it regularly. There was no litter in it. After we fixed his diabetes with insulin daily, he had more control, and I put a box upstairs in the laundry room, which he used. What amazed me, was the other cat, knew it was for the old cat only, and the younger cat, never used the upstairs box, preferring to go down in the basement in his boxes.