How does dark energy remain constant? According to cosmological constant, dark energy should have a constant density but since the universe is expanding so is the volume of the universe and so should the mass of dark energy.

But how does dark energy gain mass or energy?
Not all models of dark energy assume it constant.

However, when this is assumed true, dark energy is usually compared to the energy density of the vacuum. In other words, while the Universe expands, the dark energy increases proportionally, so its ratio with the Universe volume (the density) stays constant.

Or, better, we generally believe those models where the dark energy is a constant because they fit better our observations of the Universe, in particular the Big Bang model, which describes how our Universe evolves.

If you like some math, you can have it here.