I feel your pain.
One thing you might be stubbing your toe on: You may be thinking that ForEach is a swift command similiar to 'for each' or 'do while' in other languages like C++, JAVA, etc. It's not.
Dig deeper! ForEach is a struct in SwiftUI.
Developer Documentation: ForEach
As you know, in SwiftUI structs can have properties, computed properties, enums, and functions.
So the documentation states that .onDelete is a function within the ForEach struct. @greenamberred points out the function's signature.
Back to your confusion. You still wonder how SwiftUI knows how to pass in an IndexSet into its .onDelete function. The documentation states that the ForEach struct creates views on demand. To do this, it must have some internal private var variables to keep track of the views it creates. They are private so you can't see them, nor can you change them.
Yet, the ForEach struct keeps track of every view it creates, along with some other @State properties. So if you TAP on one or three rows, the ForEach struct will update its internal private vars. It's a pretty good guess to think that one of those private vars is a set of views that you have TAPPED. Also a good guess to assume these are stored as an IndexSet.
So, if you then execute the ForEach function named .onDelete(), the ForEach struct obliges. It has an internal set of indices of selected views AND it has the closure you want to execute. As it executes the closure, it is updating its internal variables so that it can redraw the views on demand!
If you like this answer, please be sure to subscribe to Paul's YouTube channel. It helps to drive visits to his excellent videos, and these tutorials.
PS:
This is one of the reasons why the id: \.self is a critical parameter in the ForEach struct's initializer. If your ForEach struct generates 15 views, and six of them are named "@twostraws", the .onDelete() method will have a very hard time trying to decide which one of those six views to delete. The id parameter in the struct's init() tells the ForEach struct what element makes each view unique.