Legal?
Sure. Why not? Probably never happen in a real game, but it doesn't look impossible.
If it's legal, what where the last few moves?
The b8-Bishop is a promoted pawn that has come via c6; the Black b-pawn has come from c7. The White King came to a8 earlier via the back rank, then ...cxb6, then the Black Bishop comes to a7, then cxb7, then ...dxc6, the Black King comes to c7 and finally b8=B
Legal?
Sure. Why not? Probably never happen in a real game, but it doesn't look impossible.
If it's legal, what where the last few moves?