When does normal force equal to $mg$? Can someone once and for all explain when does normal force equal to mg?
I know for sure that when there is no friction, normal force will be equal to mg.
But, i encountered some questions when there is some mass on an incline with friction, and then the normal force was the y component of mg. 
It does not make sense to me, because as i understood when there is friction, we cannot assume that mg will be equal to normal force.
 A: Briefly, the normal force is $F_N=mg$ when the surface that mass $m$ is resting on is horizontal (when the surface is inclined by an angle $\theta$ to the horizontal, then it's just $F_N=mg\cos\theta$). Friction has nothing to do with $F_N$, per se. But the frictional force experienced by $m$ sliding down an inclined plane is the coefficient of (kinetic) friction times $F_N$. It sounds like you've maybe just conflated the two ideas somehow, leading to your confusion.
A: Normal Force arises due to the Newton's Third law. 
Normal Force will be always acting opposite to the force falling on the surface.
Normal Force is a reaction force. Remember
Normal force is equal to mg only when the object is placed horizontally, and the force is acting in the direction of the gravitational field.
Now your second question
 
Here you will see that the weight of the body is passing through the Centre of gravity and acting in direction of the centre of the earth.
But the component of weight on the incline is not mg it is cos component.
In order to satisfy the Newton's third law Normal reaction to the object is the cos component
$$N=Wg\cos \theta$$ 
even if friction is there or not there this will be the same
A: Normal force $F_N$ is just the force between two surfaces. It's called "normal" because it acts perpendicular (normal) to the surfaces.
Gravitational force is completely unrelated. Gravity always acts with $F_g = -mg$. The minus sign indicates that the force points down.
These two forces often oppose each other, which is why $F_N$ OFTEN, BUT NOT ALWAYS, $=mg$. The sum of all y-components of forces must equal acceleration in the y direction (Newton's 2nd Law). For a book resting on the table, there is no acceleration in the y direction, and 2 forces acting: gravitational force and the normal force. Since $a_y=0$, $F_N+F_g=0$, and $F_g=-mg$, so $F_N=mg$.
Hairy details and garlic for the higher-ups:
"Down" depends on your coordinate system. It's more accurate to express gravitational force as a vector (although you'll have to decompose it sooner or later).
$|F_g|=mg$ only near the surface of the earth. For a more general relationship, use Newton's Law of Universal Gravitation.
Newton's 2nd Law actually states that the vector sum of all forces is equal to the mass times the acceleration of the object: $\sum \vec{F}=m \vec{a}$. This is actually 3 scalar equations: $\sum F_x=ma_x$, $\sum F_y=ma_y$, and $\sum F_z=ma_z$.
