If a phrase modifies a word or phrase that is not clearly given in the sentence, it is a dangling modifier; it is dangling because it does not connect with what it is supposed to.
In the first sentence, it is clear that the person who finished the homework and the person who went to bed are one and the same, so it is correct. In the second sentence, it is not the table that arrived late, but the speaker, so this is a dangling modifier. This could be repaired by using 'we found that the table had been taken'. Dangling modifiers can make the meaning of the sentence unclear, so they should be avoided. The subject of the main verb should be the same as the modifier in such cases.