Is the mass of wood and oxygen that allow it to burn equal the mass of ashes and the gas given off during the burning?
Yes. According to the law of conservation of mass, the mass of all the reactants must be equal to the mass of all of the products.
What is the role of charcoal in gunpowder mixture and why not ashes because I think ashes would provide more carbon than charcoal?
What is the law that explain how a pile of ashes has the same mass as the original log before it was burned?
No. If you measure the mass of the log before burning and measure the mass of the ashes after burning you will find that the mass of the ashes is less than the mass of the log. This is because the rest of the mass has been turned into gases such as carbon dioxide and water vapor that have escaped into the atmosphere. Burning a log is an open system.