Fluid mechanics I have seen the following equation of continuity for fluid dynamics for compressible as well as incompressible fluids  $$\rho_1V_1A_1 = \rho_2V_2A_2,$$
and it is derived from conservation of mass principle, but my question here is that this given equation assumes that mass of fluid in the given section of pipe is fixed, whereas that should not be true for compressible fluids, because they can have variable density, and hence the amount of mass entering the system is not equal to amount of mass exiting at all points of time.
So what's going on here? Is this equation valid for only very small local regions of a fluid, like in differential form?
 A: This equation is valid for incompressible flows (steady or unsteady), and for compressible flows in steady state. In steady state, mass inside a control volume cannot change with time, hence mass coming in must equal that going out.
A: The Law of Conservation of Mass is one of the fundamental laws in the universe. To the best of my knowledge, initially it was written for chemical reactions by a great scientist Michael Lomonsov (https://en.wikipedia.org/wiki/Mikhail_Lomonosov).
Mass of any given amount of matter can't appear or disappear, unless nuclear reactions are present.
On this premise namely, the general equation of mass conservation in fluid dynamics which you cite is derived. Note, that unless you assume that mass conserves, you cannot come up with the equation that you wrote in your question.
In case of your pipe solely, mass of the fluid contained in the section of the pipe is conserved according to the law which I cited above. It means that if I know density of the fluid in each point of the section of your pipe then $$m = \int_V\rho dV = inv(t) = const$$ See: you need to know density at each point since it's variable and not constant all over the pipe section. 
Now, how can I provide constant mass inside the pipe section? Fluid in the pipe section is provided by the flow in the pipe. Therefore, if mass of fluid entering the the pipe section during 1 second equal the mass of fluid exiting the pipe section during 1 second then mass of fluid inside the pipe section doesn't change. Since, the flow is compressible, density of the fluid at inlet and exit of the pipe section is different. But as it is stated above, mass entering and exiting the pipe section should be the same. THAT IS WHY, VOLUME of fluid entering and exiting the pipe section is different.
In order to maintain the same mass in the pipe section taking into account that density varies, you merely regulate the volume of fluid which goes in and out of your pipe section.
And it is intelligible: if density at the inlet of the pipe section is higher than the density at the outlet of the pipe section it just means that the same mass is packed into different volumes at the inlet and at the outlet.
NOTICE: 
1) I didn't write that "fluid is compressible" - I wrote that "flow is compressible", that is because fluid cannot be compressible or incompressible; in fluid mechanics only flow can be assumed incompressible under some conditions;
2) I was talking about mass per time entering/exiting the pipe section;
3) When we speak about pipe section, we imply control volume in which fluid is contained. Mass of fluid withing control volume can change in some problems (but not in yours); but when we speak about The Law of Mass Conservation, we speak about substance itself - not about the control volume where this substance is contained.
