Because our body needs sugar "all the time" and it can't rely simply on what we eat to put sugar in our blood at times when we are not eating/digesting food
So our Liver stores, produces and releases sugar to fuel all our organs, brain, muscles etc
The rate and how much it releases is dictated by various hormones in the body. If one of our (systems) needs fuel a given hormone will signal the liver to "release some sugar"
That process is quite complex and it can be driven by everything from need to keep the brain fueled to a hormone response to stress or fear
The reason why more complex cases of Diabetes are treated by Endocrinologists is because quite simply they are "hormone doctors" and in some cases of Type 2 our blood sugar (problem) is the result of a hormone imbalance or deficiency rather than what we stick in our mouth.