I really imagine what you are going through regarding your loss.
I am and ER physician and 25 year in the profession and have had to deal with issues like yours.
The direct answer to your question is that AUTOPSY should be able to determine the factors related to demise of your baby in utero. Most of time AUTOPSY can only show STRUCTURAL abnormalities (like the trilobe left lungs), but there must have been genetic and metabolic factors that created the environment for the structural abnormality, AND also the structural abnormality may have triggered metabolic abnormalities that would make it difficult for the fetus as it grew older integrating functional survival.
So it is going to be difficult to find the SPECIFOIC cause of the demise.
Regarding 'why wasn't it detected, mid trimester ultrasound which is done to TRY TO FIND fetal abnormalities, mostly tend to specifically look for gross, KNOWN life threatening structural abnormalities and chromosomal abnormalities like Downs syndrome, heart deformities, brain defects. AND because the lungs are NOT used in the womb, its not active to appoint that IT CAN EASILY be scanned, except IF they are specifically looking for something.
While, I imagine, that no explanation can completely explain what might have happened, I have given you the scientific facts as we can. There lies the occasional moments when medical science cannot provide the most important answer of why, and how.
There has been lots of research on this subject, including even babies who are born healthy, and there are so many possibilities, that would only deepen your frustration