If illegal, since when?
(If any readers are curious, here is an example: 8ec3e3dd39150798d71c61ffb7cc18ade6f2a2958378e18b7a98eefb709e7322 spent by f21b099d67070a7639d384f30e9b139bab58c27e47368a2d8152f05c14e187b7 which is the smallest tx record)
A script has to be standard or the transaction won't be accepted, this check is done with the
isStandard() boolean function which will return false if the
Solver function returns `TX_NONSTANDARD`.
The `Solver()` function will return `TX_NONSTANDARD` if the script is not P2SH, or valid WITNESS, or OP_RETURN, or P2PK, or P2PKH. None of them can be empty, thus a transaction with an output containing an empty scriptPubkey will be non standard and thus not accepted (/illegal).
EDIT : To answer the question in the title, "nonstandard or illegal ?", this is the same : only standard scripts are legal.