Copyright applies from creation: an unpublished work is still protected, although proving its origin will likely be easier following publication. The US Copyright Office summarises it as:
The law automatically protects a work that is created and fixed in a tangible medium of expression on or after January 1, 1978, from the moment of its creation and gives it a term lasting for the author's life plus an additional 70 years.
The law automatically protects a work that is created and fixed in a tangible medium of expression on or after January 1, 1978, from the moment of its creation and gives it a term lasting for the author's life plus an additional 70 years.
https://www.copyright.gov/circs/circ15a.pdf