It is said that the CBC-MAC is simply the last block of ciphertext if the message is encrypted using CBC block cipher mode, and I don't understand what this means
What you show in the question is a mathematical description of the CBC MAC mode. However, this question is easier to understand if you look at the CBC-MAC picture on Wikipedia:
Benjamin D. Esham (bdesham) - Own work based on: Cbcmac.png by en:User:PeterPearson
Normally the ciphertext blocks are simply the ciphertext output for each $E$ function in the picture.
Note that there are two other differences with CBC mode as it is commonly used:
- the all-zero IV and
- the bit padding mode is used, usually PKCS#7 compatible padding is used instead (not showing in the picture, not in the indicated algorithms).
The all-zero IV is not shown in the picture you've posted. I'd also stipulate that if the message size is zero the MAC output is not just the IV. Instead, because bit padding is always applied you would simply send an encryption of the bit padding. So in that sense, the formula is erroneous.
How does encryption with CBC even work for schemes such as this where encryption is nested. Do we work from inside to out and use the previous result as the input message block?
Yes, however in that case such a nested structure in your picture does not make much sense, as you would get output for each iteration.
Again, I'd not even say that the IV is part of the ciphertext, so the formula would simply be:
$$c_i =
\begin{cases}
E_k(IV \oplus p_0) & \text{if } i = 0 \\
E_k(c_{i - 1} \oplus p_i) & \text{if } i \neq 0
\end{cases}
$$
It should be clear that if you take the final ciphertext $c_n$ and then iteratively substitute $c_{i-1}$ with the definition you get back your CBC-MAC formula - except for the erroneous IV part as indicated.
Or you could again create a picture such as above (compare this with the first picture shown in the answer!):
WhiteTimberwolf (SVG version)