In 87Rb, the Fermi level for spherical shape is very close to both f5/2 and p3/2. We do expect 87Rb to be spherical, because the neutron number is magic. Therefore we expect a 5/2- state and a 3/2- state, both of them very low in energy. One of them should probably be the ground state, and the other the first excited state. This is what we see when we look up the nucleus in ENSDF. So there is really no huge surprise here. You just can't take these diagrams of single-particle energy levels as if they were guaranteed to give exact predictions for all nuclei. A paper discussing the nuclear structure is here. The relevant discussion is on p. 3.
Because 40K has only a single proton hole and a single neutron outside of the closed shell at particle number 20, we again expect it to be spherical. However, odd-odd nuclei are a mess because there are lots of ways of putting together states for the two odd particles. 40K has a 4- ground state, but it also has a known 3- state at only 30 keV excitation energy. There may be a dozen more states within 100 keV above the ground state which just haven't been detected. There is no easy way to sort out which should be the actual ground state theoretically, short of doing a full shell-model calculation ("shell model" meaning you actually diagonalize the Hamiltonian for some interaction among the valence particles, not just assign particles to states up to the Fermi level). Even a shell-model calculation is unlikely to get things right to a precision of 30 or 100 keV. ENSDF says for the ground state:
Dominant configuration=π1d3/2−1⊗ν(1f7/2 or 2p3/2) (2014Pa45) from comparison with shell-model calculations.
However, this doesn't quite make sense because you can't couple spins 3/2 and 3/2 to make the observed spin 4 of the ground state, so I think the ENSDF evaluator made a mistake interpreting the paper they refer to. On p. 8 of that paper, they seem to be saying that it's π1d3/2−1⊗ν1f7/2. The spins 3/2 and 7/2 can couple to make anything up to spin 5, so spin 4 is possible.