Why we need the declaration and
Historically? It provided a way for a validator to know what elements and attributes were allowed where and for a parser to expand entity references.
HTML 5 gives up on this idea and has a simpler Doctype that does nothing except trigger standards mode (see below).
Is the declaration affect style?
Browser venders, as they were coming out of the era of "having lots and lots of bugs" decided to use the Doctype as a heuristic to determine if the author of the page knew what they were doing.
With no Doctype, they decide that the author doesn't know what they are doing and emulate a lot of ancient bugs. This creates a lot of inconsistencies in how different browsers render a given page. This is called Quirks mode.
With a Doctype (except for certain Doctypes), they decide that the author does know what they are doing, and try to render the page as close to how the standards say as possible. This is Standards mode.