If charges is quantised, how can we use integrals in electrostatics?

You may also wonder why we use the concept of density of a material despite that material is made of molecules, or atoms, or in general quantized entities. This is the basis of hydrodynamics and solid mechanics (we use differential equations and integrals even if there are atoms). Electrostatics is just another branch of the "physics of continuous media".

Second, it is also worth to remember that we discovered that the charge is quantized after we developed electrostatics (the Millikan oil-drop experiment has been made in 1909, the Coulomb law dates 1785): in fact, in our macroscopic world almost everything can be described as a continuum. In classical electrodynamics you do not need to know that charge is quantized, simply because you do not see the effects of quantization (for the same reason why you do not see the single grains of sand when looking at a beach from a certain distance).

The basic concept is that of using a "fluid element", namely a small piece of matter containing many "atoms" that is big with respect to the microscopic length scale (so that its average properties like "density" are well defined) but that can be considered a point from the macroscopic perspective. Clearly, the "microscopic length scale" is the average (typical) distance between the discrete entities that compose your fluid element.

In general all the classical mechanics of continuous media is made in this way. After all, also car traffic in cities can be described (to some extent) in terms of differential equations and integrals, despite cars are quantized (see e.g. "traffic flow").

When you first learned calculus, you probably had the misconception that you use very large to approximate the infinite or the very small to approximate the infinitesimal. This is wrong.

There are almost no physical circumstances which you approximate the infinite by the very large or the infinitesimal by the very small.

The correct approximation is the other way around.

You approximate the very large by the infinite or the very small by the infinitesimal and NOT the other way around.

This is just another situation of that. Charges are very small so we approximate them as infinitesimal. Why? Because calculus lets us make very accurate calculations.