As you state yourself, the distinction between the two tenses concerns the time when the homework was finished.
So, let us surmise that this conversation takes place at 19.00, that A went out at 18.00 and that A had started doing his/her homework at 17.00.
(Note the use of had to emphasise the sequence of events.)
In example 1, B asks A whether his/her homework is NOW (at 19.00) complete.
In example 2, B asks A whether his/her home WAS complete (by 18.00) when A went out.
Both constructions are correct. They just mean different things.
B might also have asked A:
Did you finish your homework
but this wouldn't make it clear whether the work had been completed before or after A went out.