Yes, CE also applies to machines. However CE is not a certification, it is self assigned.
This works well in most cases because companies risk financial consequences or even prosecution if they bring a product on the market that doesn't comply with various rules related to functionality, safety, chemicals, electromagnetic behavior and so on. These are all written down in standards that can be used to comply with lawful regulations and directives.
For products imported from outside of the EU the same rules apply. The importer or representative in Europe can be prosecuted. However governments almost never check products proactively which causes a lot of shit to enter the market. So what really needs to happen is to enforce the rules.
It is. It is just not enforced. The scale at which consumers import products in Europe is such, that no government agency can ever check these products.