I created the following sentences.
- During this process, a lid covers the opening of the container to prevent entry of water into the container.
- During this process, the opening of the container is covered with a lid to prevent entry of water into the container.
I know those like the second sentence are widely used, but I am unsure that the second sentence is grammatically correct because the subject (the opening) of the sentence does not agree with the subject (a lid) of the to infinitive.
The to infinitive in the second sentence may be considered as an adjective to modify a noun "a lid", but I think such an interpretation makes the sentence strange.