My wife insists that her sweetpeas have produced pea pods without having produced flowers. I told her that that is not possible.
Before I divorce her I thought I hd better check to see if there was some variety or some condition that causes tiny, not noticeable flowers.
This would be physically impossible, as this is where the pods come from. I could see a situation where it produced insignificant flowers, or possibly self pollinated before they opened fully. But to answer your question: You must have flowers to have pods.
Here is an article for how to properly harvest the seeds: https://www.gardeningknowhow.com/ornamental/flowers/sweet-pea/collecting-sweet-pea-seeds.htm