Here's why:
* Luna was captured by Death Eaters: During the Battle of the Department of Mysteries, Luna was captured by Death Eaters along with Harry, Ron, and Ginny.
* Harry escaped with the others: Harry escaped the Ministry with Ron, Ginny, Neville, and the other members of Dumbledore's Army who were present.
* Luna was rescued later: Luna was rescued from the Department of Mysteries by Dumbledore's Army members, but she was not part of Harry's escape group.
Therefore, Luna was not with Harry at the end of the battle. She was rescued by the other members of Dumbledore's Army after Harry and his friends had already escaped.