Can I replace "that is/are (supposed) to" with just "to"?
Is this sentence grammatically correct?
[This method] binds a handler to one or more events to be executed once for each matched element.
source
Is it just a contraction of the following sentence?
This method binds a handler to one or more events, that is (supposed) to be executed once for each matched element.
Solution 1:
The sentence is grammatically correct, mostly (it wants a comma after events, to make clear that it is the handler which is executed).
The expansion is a little trickier. Your first level of expansion is correct:
handler ... to be executed < handler ... which is to be executed
However is to be should not be parsed as an ellipsis of is supposed to be (or expected or desired or anything else of the sort). That's what the idiom means, but it's not how it came to be.
(Before I take this any farther I need to enter a caveat: I'm not a scholar of OE. I only know this stuff because I had occasion to look it up last week in the course of the discussion of this question, so anything I say stands under correction by those more knowledgeable.)
If you look up this use of be in OED 1 you'll find it under senses 16 and 17:
16.With the dative infinitive, making a future of appointment or arrangement; hence of necessity, obligation, or duty; in which sense have is now commonly substituted.
17.The same construction is used in the sense of 'to be proper or fit (to)'. . .
That 'dative infinitive' refers to an OE construction which has been lost except in 'fossilized' expressions like this we're discussing. OE had I believe no distinct gerund; instead it employed what we now call the 'bare' infinitive and applied the appropriate case-ending. The idiom at hand employed to, which at that time was the ordinary preposition and took the dative case. For instance, OED's first citation under sense 17 is this:
c. 1175 Lamb.Hom. 133 Hit is to witene.
"It is (proper or fit) to know . . . " witen is the infinitive, and -e is added to mark the dative.
Of course, when English lost its case-endings (and acquired its gerunds), the underlying grammatical structure vanished from sight. We now parse the to as an 'infinitive marker' and the verb as a 'bare infinitive'. And that leads to just the sort of perplexities you'll find in the comments to the question I link above.
Because the idiom itself lived on, and evolved: notably, by the end of the 16th century it had been analogically extended to the passive voice, which is how your example uses it.
The same deep history lies behind the idiom have to (alluded to at the end of the sense 16 definition), which has an even more complicated recent history.
But what it all comes down to is that handler (which is) to be executed is complete and meaningful as it stands, and requires no further expansion.
(I love the English language.)
Solution 2:
It is perfectly grammatical.
It is a common construction, and can certainly be analysed as a contraction of "which is ... " or "that is ...". I don't know whether that analysis is currently favoured in the academic world, or whether it is regarded as a seprate construction with equivalent meaning.
You're also right that the construction "to be Xed" has an implication of "supposed to".