If you open the system to air, when shortening hydraulic hoses for example, this can lead to brake fluid loss and air entering the system. Damaged brake lines, joints, perished seals and leaks can also be to blame for air entering your brake and causing your lever to feel spongy.
Sometimes even a brand new brake, or the brakes fitted to a new bike will need to be bled of air if the brakes have been inadequately filled at the factory during production or your bike shop has failed to carry out the work for you.
Brakes that use DOT brake fluid are more prone to water or moisture ingress. DOT brake fluid is hygroscopic by nature which means it absorbs water from the environment via seams and microscopic pores in your hydraulic lines. This water content has an adverse effect on the performance of DOT brake fluid by reducing its boiling point.