An M-QAM modulation contains M different constellation symbols. Hence, in one symbol you can encode $\mu=\log_2(M)$ bits. (i.e. 6 bits for 64-QAM for example). Now, the bits are equally distributed along the real and the imaginary part of the constellation, i.e. you have $\frac{\mu}{2}$ bits for the real and imaginary part. To encode $\frac{\mu}{2}$ bits, you need $2^{\frac{\mu}{2}}$ different amplitude levels (i.e. 2^3=8 for 64QAM).
Another explanation for the relation of amplitude levels and M: Your M constellation points are arranged in a square. Hence, each side of the square contains $\sqrt{M}$ elements. These are your number of different amplitude levels.
Regarding why the amplitudes have the values of (-7, -5, -3, -1, 1, 3, 5, 7) for 64-QAM. These numbers occur due to two reasons:
- the distance between adjacent symbols should be constant (with these numbers the distance is 2). Otherwise, different symbols have different "quality" or error rates. This would be unfair and also does not achieve the optimal distribution in terms of channel capacity.
- the constellation should have zero mean (otherwise you would use power for transmitting the mean which does not contain information).
From these two criteria and the addition that you always have an even number of amplitude levels, you actually find that the amplitudes need to be symmetrically distributed around zero. Then, the simplest possibility is to use the values (-7, -5, -3, -1, 1, 3, 5, 7). However, also (-7/2, -5/2, -3/2, -1/2, 1/2, 3/2, 5/2, 7/2) yields a correct 64QAM constellation.