Is it safe to wire a plug-in sconce directly to the junction box?
Not safe, not advisable.

It would not pass an electrical inspection, because the wire is likely exposed for some distance (before it enters the box), and the wire composition (jacket) may not be rated for in-wall use.  Another problem is the mechanical fastening (clamping) of a 2 wire cord into a junction box.  Romex cable has a sheath, with wires that are identifiable as hot, neutral and ground wire, your configuration will not.   You could easily connect the hot wire to the threaded part of the socket.