Is it permissible for one to masturbate in order not to commit fornication?
This is called committing the milder of the two evils such as eating a carcass in fear of death, and this happens when committing fornication is very likely to occur.
What is the torment of the grave?
We seek refuge in Allah from the torment of the grave. The important point is that the cause of the torment of the grave is disbelief or committing sins without repentance. It affects the soul, and the body is impacted by it, even if we do not see it. And Allah Knows Best.
Is the marriage contract considered valid if concluded at home by the marriage official (Ma`zon)?
Yes, it is valid as long as it is registered at the court.
Is wearing a cap permissible for boys, or girls?
All Perfect Praise is due to Allah, The Lord of The Worlds.
In principle, anything is permissible sol long as there is no Sharia evidence prohibiting it, thus wearing the cap by boys is permissible as long as it isn`t done in imitation of the disbelievers. Moreover, a Muslim woman should avoid all that which attracts the attention of men because whatever leads to the forbidden is forbidden. And Allah Knows Best.