Your solar battery charges from the grid due to insufficient solar generation. Insufficient sunlight, panel shading, or system capacity issues can lead to reliance on the grid for charging.
Alternatively, your system may be set to charge during cheaper, off-peak hours to reduce costs. So, if your energy tarriff is half as cheap at night, you can charge then and use the energy during the day instead. All perfectly legal, and a whole lot cheaper!