Functions can return new class definitions- the "class" keyword represents an expression, not a statement.
As such, you could write a function that takes in as an argument a class, and return a new class definition that extends the argument you provided... Or any number of other dubious practices.
Decorators are syntactic sugar for higher ordered functions. They fundamentally have the same capability, just with better ergonomics.