Potential Energy of a System and work–kinetic energy theorem If you lift a book from the floor to a shelf, $K_f-K_i=0$,because the final and initial speed are 0.
So from the work–kinetic energy theorem the work done by external forces should be $0$, so there is no energy transferring mechanism here, since  work done by external forces is $0$, and there is no other energy transferring mechanism here, so how does this the system gain energy in form of potential energy?
 A: 
. . . so how does this the system gain energy in form of potential energy?  

The system which gains the gravitational potential energy is the book and the Earth not the book alone.
You do work increasing the separation between the book and the Earth and the result is that the book and the Earth have more gravitational potential energy.  
The book alone as the system has two forces acting on it.  


*

*The gravitational attractive force due to the Earth.

*The upward force that you exert.


So the net force on the book is zero, the net work done on the book is zero and so the change in kinetic energy of the book is zero.  
Put another way the positive work done by you in lifting the book is equal to the negative work done by the gravitational attractive force.
A: You lifted the book. You are the external force supplier.
$W_{gravity} + W_{ext} = \Delta KE = 0$
$W_{ext}=-W_{gravity}$
The relation given when mechanical energy is conserved is a special modification of the work energy theorem when there are only conservative forces acting on the system.
$W_{conservative} + W_{non-conservative}=\Delta KE$,
When $W_{non-conservative}=0$,
$W_{conservative} =\Delta KE$,
Positive work done by conservative force decreases the potential energy of the system and negative work done increases the potential energy.
Therefore, $W_{conservative}=-\Delta U$,
$-\Delta U = \Delta KE$
$\Delta KE + \Delta U=0$
A: The work done by external forces is zero. Your hand which lifts the book does positive work on it. The force of gravity does negative work on the book while you lift it. Since there is no change in kinetic energy, they exactly cancel each other out. The reason that you might be confused is because the work done by gravity is actually defined as the negative change in the gravitational potential energy (i.e. $W_{g}=-\Delta PE$). Therefore, gaining gravitational potential energy is exactly equivalent to having negative work done on you by gravity.
Edit: Here is a brief derivation of the Work-Kinetic Energy Theorem which relies only on a couple of basic definitions.
$$\Delta E=\Delta KE \ + \Delta
 PE \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{(Definition of Mechanical Energy) (1)}\\ W_{total}=W_{conservative}+W_{non-conservative} \ \ \ \ \ \ \ \ \text{(Mutually exclusive categories) (2)}\\ W_{conservative}=-\Delta PE \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  \ \ \  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{(Definition of Potential Energy) (3)}\\ W_{non-conservative}=\Delta E \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{(Definition of Non-conservative Forces) (4)}\\W_{total}=\Delta E-\Delta PE \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{((2)+(3)+(4)) (5)}\\W_{total}=\Delta KE \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{((1)+(5)) (6)}$$
As you can see, this derivation (and therefore the W-KE Theorem) is entirely agnostic with regards to whether the forces are internal or external to the system. The only thing that matters is whether ther forces at play are conservative or non-conservative.
A: By work - kinetic energy theorem you presumably mean something like:

The work-energy theorem states that the work done by all forces acting on a particle equals the change in the particle's kinetic energy

But this is true only when there is no change in the potential energy. A more complete statement would be:

The work-energy theorem states that the work done by all forces acting on a particle equals the change in the particle's kinetic energy + the change in the particle's potential energy.

In the example you give there is no change in kinetic energy since the particle is stationary to start with and stationary at the end of its motion. In that case all the work goes into changing the potential energy.
A: There is a mistake in your approach: the final velocity is not zero. If you are measuring that movement, according, of course, with the point particle model, the module of the velocity vector is such that $K_{f}-K_{i}>0$ in the moment of the contact between the particle and the shelf. In that instant of time the trajectory is complete, and then we stop our clock, and no later.
