The window opens "out to" or "up to" sounds more correct if you ask me.
Why is " sopra il cortile " wrong ?
That would be literally 'on top of the yard', which is an indication of place that is incorrect here. The use of 'sul' is idiomatic here, I assume.
What is the difference between la cortile and il giardino in this context?
Giardino means garden. Cortile means yard, which I guess could contain a garden, but is generally a larger space not necessarily for growing flowers.
I suggest the translation "la finestra dà sul cortile". It's used in elegant italian.
I would have said giardino and not cortile for yard