I think this question goes to the core of what it means to be a Buddha, i.e. what it means to be Awakened, i.e. what Awakening (also known as Enlightenment) means.
Different spiritual traditions have different takes on the concept of Awakening and I am not an expert on exactly where the word “bodhi” or the concept of Awakening comes from, wether it’s an originally Buddhist word and concept or wether it’s borrowed and reinterpreted from earlier traditions.
However, it seems quite clear to me that in Early Buddhism as taught in the Suttas, Awakening is synonymous with the “Knowledge and vision of freedom” AN 10.1, AKA “Knowledge and vision of ending” SN12.23, AKA “Knowledge of the destruction of the defilements” MN 51.
The destruction of the defilements comes through disillusionment and dispassion, which comes through true knowledge and vision, which comes through right samadhi, which comes through… ethics! (AN 5.24)
How are ethics fulfilled?
Through giving up greed, hate and delusion.
How are greed, hate and delusion given up?
Through the cultivation of the higher ethics, higher mind and higher wisdom (the Noble Eightfold Path):
“So, monk, you should train in these three trainings: the higher ethics, the higher mind, and the higher wisdom.
As you train in these, you will give up greed, hate, and delusion. Then you won’t do anything unskillful, or practice anything bad.” (AN 3.84)
How does one train in the higher ethics?
By keeping the precepts:
And what is the training in the higher ethics? It’s when a mendicant is ethical, restrained in the code of conduct, with good behavior and supporters. Seeing danger in the slightest fault, they keep the rules they’ve undertaken. This is called the training in the higher ethics. (AN 3.90)
Why should one keep the precepts?
Because acts born of greed, hate and delusion only give rise to more greed, hate and delusion (AN 6.39)
It is not possible to do an immoral act “without attachment”. I think in this case people confuse “without attachment” with “without remorse”, or “without guilt” or “without caring about the consequences”. That’s a different thing.
Immoral acts can only be done if there is greed, hate or delusion (AN 10.174), wether one is aware or not, destroying vital conditions for advancing on the path to Awakening.
For a Buddha (or an Arahant)
…bad unskillful qualities born of greed, hate, and delusion are cut off at the root, made like a palm stump, obliterated, and unable to arise in the future. (AN 3.69)
So, according to Early Buddhism, no, there cannot be an immoral Buddha (or Arahant).