All are grammatical, but some are more idiomatic than others, and there are differences in meaning.
When did you read a book last time?
This is not idiomatic. The structure, with "last time" as an adverbial phrase at the end, suggests that it is not asking about the last time you read a book, but about when you read the book during the last occasion which was like this (or like something already referred to). It might appear in a conversation like:
Now I'm on holiday, I've got a book to read; but I haven't decided whether to do that in the morning, the afternoon, or the evening.
When did you read a book last time?
meaning "the last time you were on holiday", and the "when" is locating the reading within that period.
When did you last read a book ?
This is the normal idiomatic way of asking the question.
When did you read a book for the last time?
This is not idiomatic, and suggests the other meaning of "last": not "most recent", but "final". It's not a likely thing to say in that meaning, so it would probably be understood in the intended sense; but it's a bit confusing.
When was the last time you read a book?
This is completely idiomatic, and means exactly the same as "When did you last read a book".