You could, but if you think a bit more about it, why would you? If you're putting together a frame there will be the inevitable cleaning up around the joints with either a cutting tool of some sort (e.g., chisel) and/or water, and/or flushing off two parts that are slightly out of level, e.g., a rail with a stile, or a rail with a leg, or a panel glue-up. All of those cleaning up efforts will either affect the colour of dye or stain, and/or will reveal the raw wood. Patching such areas is tricky.
It's best to learn how to apply colourant plus all other finishing procedures to assembled parts which have been prepped for finishing usually both before and after assembly. It's rare to be able to pre-finish prior to assembly (dye, stain, polish, etc), although partially pre-finishing all faces and edges of both board material and solid wood panels that go within frames glued around the panel is normal, and doing so prevents any wood shrinkage revealing undyed/unstained/unpolished surfaces covered by the framework's groove and moulding.
Pre colouring with water based dye doesn't affect glue, but pre-colouring with pigment stain might because stains generally include smallish quantities of either linseed oil and/or linseed oil and resin to act as a binder, which most glues don't adhere to very well, so even a small amount of this stuff that gets on to joints can compromise glue strength at least a little. Slainte.