Light is emitted from flames by two primary mechanisms: one is small particles glowing incandescently because they are hot (the same mechanism that drives an incandescent light bulb); the other is from electronic transitions from specific energy levels in excited atoms in the flame produces as a by product of the combustion process (this is partly why flames can coloured specifically by elements present in the burning material).
But why do flames and their emissions appear so far from the primary materials that are burning? Clearly solids themselves can burn (eg charcoal in a barbecue is glowing from surface combustion of the carbon with atmospheric oxygen and the emission you see is because this makes the carbon hot enough to glow with heat).
But when things are that hot, plenty of other reactions can occur and this is particularly noticeable if the thing that is burning is less pure than charcoal (which is mostly carbon). Raw coal, for example, contains a lot of volatile impurities (smokeless coal is deliberately treated to reduce the volatile impurities). When the primary reaction of burning carbon happens in raw coal, those volatiles are often turned to gases and driven off the coal to combust as gases far from the solid coal. Of course this is happening at the same time as solid carbon in the coal is burning so the two effects are mixed up to give both glowing coal and gases burning some distance from the glowing coal. Old home chemistry sets used to contain experiments that allowed these effects to be separated. Raw coal is placed in a vessel connected to a tube allowing any emerging gas to be directed far away from the coal. The coal is heated with an external source (eg a Bunsen burner). The emerging volatile gases can then be lit without setting the coal on fire giving a flame a long distance away from the heated coal.
The same can be done with wood (which contains even more volatile and flammable components than coal).
So, when wood or coal burn in an uncontrolled way both the burning of the solid and the burning of the volatiles contained with the solid occur at the same time but the volatiles (as gases) can move far from the solids before they burn. This is why the position of the fame can be far from the burning solid.
Also worth noting
In addition to the volatiles being driven from the burning solid, partial combustion can also create gases like carbon monoxide which can then travel some distance away from the solids while burning (though CO tends to have not very bright blue flame). In fact a controlled version of this reaction (which sometimes also used steam to create hydrogen) was once the primary way of creating town gas (which was widely distributed to support gas lighting and cookers in cities.
If the primary goal is to create flames designed to illuminate rather than heat then burning can be designed to create a lot of small hydrocarbon particles in the flame. This is intentional for things like candles. Here the heat may come from burning the was but the light comes because that burning creates small incandescent soot particles which are heated enough to glow turning a lot of the energy into light.