Much of the flavour of brewed coffee comes from volatile oils. Raw coffee beans keep them safely confined, but roasting then grinding them exposes a relatively huge surface area to the surroundings.
https://www.newscientist.com/lastword/2522837-why-dont-coffee-bags-make-very-good-coffee
