Why does Stockfish undervalue pawns when compared to the classical "a piece is worth three pawns" approach? I was taking a look at values engines give to pawns and piece and was quite shocked by Stockfish values for middlegame (Mg):


PawnValueMg   = 128
KnightValueMg = 721 ~ 5.6 pawns
BishopValueMg = 825 ~ 6.4 pawns
RookValueMg   = 1276 ~ 9.9 pawns
QueenValueMg  = 2538 ~ 19.8 pawns


So this is way far from the standard "1 piece equals 3 pawns approach", and I was curious about the reason behind it.

Also, the fact that bishops are 0.8 pawns more valuable than knights called my attention.

I'm aware that this is a small part of Stockfish's (or for that case, any serious engine) evaluation function, but even so it seems like a really big different from the classic approach.
I am not an expert on stockfish source code, but my understanding is the following.

Humans:

It is true, that the  1 piece equals 3 pawns approach is pretty accurate, surprisingly so. However as you are probably aware, when evaluating a position, we consider many other aspects as well, such as piece activity, space, king safety, etc. The difference however is that we don't assign actual numerical values to these other factors. 

Stockfish (or similar engines):

Unlike humans, engines assign numerical values to all factors. The numbers you mention are just a small part of the evaluation function.

Check out the middlegame evaluation function for stockfish. On that page you can also modify the board to see the evaluation and you can visit the specific functions such as `piece_value_mg' which is concerned with these numbers.

As you can see, just the piece values of all pieces amount to 9326. However there are many other functions which add to the evaluation. Most importantly, not all of these extra functions treat pawns and pieces equally. 

For instance: 


`Psqt mg', gives values to pawns only, depending on their position on the board. As you would expect,  pawns in the center are more valuable (pawn on e4 instead of e2 is +24 points)
another pawns only function: `Pawns mg' gives points depending on the pawn structure (isolated, doubled, connected pawns, etc) also here you can gain several tenth of points for the pawns (but not for the pieces).


To be fair, there are also functions that only deal with pieces such as `Pieces mg'. However note that they can also give a penalty (negative value) to the total evaluation. In fact for the starting position you have -63 from that function.



In summary...

Stockfish has a much more fine grained evaluation function than we humans do. The pure piece value from stockfish cannot really be compared with the human piece value.

In stockfish pieces and pawns can gain points in other ways beyond the values you mention. Furthermore, stockfish does not consider the piece on its own, but also how it relates to other pieces, e.g. whether there are doubled pawns, an outpost, etc.

If you check out the code, these other factors are each in the range of several ten points, so if you take them all together you might very well gain the 100 points necessary for the pawn to be 1/3 of a piece.

Mathematically you could also consider it as a kind of approximation or averaging in which you assign a single number (human piece value) for the very complex system that stockfish uses. There is no reason that the average value (human piece value) has any relation to one of the parameters (ValueMG) in the stockfish universe.

I really recommend to see for yourself at the link how much more complete the stockfish evaluation is.