The phrase brand spanking new means to be entirely new or recently created, and was first recorded in 1860. It evolved from the compound word brand-new and the phrase spick-and-span. Also, spanking, while the main definition is to hit someone on the butt, can also mean to move quickly. So one might say that a brand spanking new object was created quickly or appeared very fast. In truth, no one knows quite how it was coined or what it originally referred to.
This idiom is not officially recognized in most dictionaries, and as such does not have an official spelling. Most instances are hyphenated, since the phrase is used as a compound adjective. Though since hyphens in general are on the decline, an argument could be made for not using them. There are some publications which prefer hyphenating brand-spanking and not new, so that it is new that is being modified.