Depends upon your hard­ware and OS version.

Here in my 9‑current with ATA via CAM I can use e.g. “cam­con­trol iden­ti­fy 0:0:0” to see the sta­tus (“write cache”). I do not know of a way to change the write cache set­ting from the com­mand line, but I think the loader tun­able “hw.ata.wc” is hon­ored by ATA via CAM too (set it to 0 to dis­able the write cache for all disks man­aged by the ATA part).

For my USB mem­o­ry stick I can get a list of “mod­e­pages” via “cam­con­trol mod­e­page 4:0:0 ‑l”. It shows 0×08 as the “Caching Page”, so “cam­con­trol mod­e­page 4:0:0 ‑m 0×08” gives me the sta­tus for it (WCE means “Write Cache Enable”). To change this mod­e­page add “-e” to the pre­vi­ous com­mand line (I doubt any consumer-grade USB mem­o­ry stick has a write cache, but you can use this for USB attached disks).

For ATA hard­ware not con­trolled via CAM, have a look at the atacontrol(8) man-page how to deter­mine the cur­rent sta­tus of your disks.