Why is my sugar in my recipe becoming gritty and dry after baking in the oven. This is something new for me
I'm guessing this is for some type of fudge or praline?
There are a lot of variables that can change the crystallization of sugar when making a sugar syrup. Things like temperature, how clean your pot is, whether a wooden spoon is wet, how fast and when you stir, etc.
Using an interfering agent like butter or cream helps prevent the solution from creating large crystals. But even with those agents undissolved sugar or impurities can grow into large crystals.
Without seeing what you're cooking and how you're cooking it I can't give you a direct answer. But the best course of action you can take is to pay particular attention to cleaning and drying your pot, the implement you use to stir, and the complete dissolving of the sugar during the initial creation of the syrup.
This article has a lot of good information on sugar syrup and may point out something you're doing that could be done better.
https://www.finecooking.com/article/learn-how-to-control-crystallization-for-successful-sweets