You haven't mentioned any particular holiday or reason for buying the gift. Because your question has been posted on December 24th I think many would assume you are talking about a Christmas present, but I'm going to answer in a more general way because I don't think the season or reason matter, plus I hope to be more useful to future readers.
I suppose the two reasons you might consider consulting with a parent before buying a gift for their child is (i) to check it is okay to even buy their child a gift, and (ii) if it is okay, what kind of gift they might like.
Regarding the first point - I don't believe there is anything unusual about buying a gift for the children of your friends or relatives. It might be considered a little bit unusual if an adult bought a gift for a child of someone whom they do not know well. Perhaps a benchmark for that might be to ask yourself if you would buy their parent a present or not. If the parent isn't on your gift list, it might be a bit odd to put their children on it. This certainly isn't a rule, and there would be many situations where it would not even raise an eyebrow. For example, a work colleague of mine once made a small gift for my daughter, whom she has never met. I talk about my daughter a lot at work, my colleagues know her likes, and this particular colleague does crafts as a hobby so it did not seem in any way unusual that she did this gesture.
If you ask the parent what kind of gift to give their child, you face a couple of potential issues. They may out of politeness tell you that there is no need to buy their child anything. You may also run into the awkward situation that the parent has a number of things they would like to buy for their child themselves, and you may be taking that away from them. On the other hand, if you don't ask what they want and you just go ahead and buy the latest cool thing that every kid wants then (a) they might already have it, and (b) you may again be stepping into the parent's territory.
On the matter of whether or not you should buy a gift, my advice would be to not ask the parent but rather ascertain yourself whether or not it is appropriate.
On the matter of what to buy them - avoid duplicating what they may already have and what their own parents might want to buy them and choose something unique yourself. Many agree that the best kind of gift is something that the person would hopefully either want or find useful, but is not something they would buy for themselves. So think of something you think is cool. Another example from my own life is that my wife's friend always buys a small token gift for my daughter whenever she visits. It is usually something unusual, like a craft project, and because it is unexpected it is always well received.