An [n,k,d] code is distance-optimal if its minimum distance cannot be improved, i.e. if there does not exist an [n,k,d+1] code. A stronger condition is as follows: an [n,k,d] code is length-optimal if its length cannot be improved, i.e. if there does not exist an [n-1,k,d] code.

I call an [n,k,d] code optimal if it is length-optimal, and there exists neither an [n+1,k+1,d] code nor an [n+1,k,d+1] code. Other people use the word optimal in slightly different ways.

The motivation for this definition of optimal is the following list of assertions, all easily checked:
If there exists an [n,k,d+1] code, then there exists an [n,k,d] code.
If there exists an [n-1,k,d] code, then there exists an [n,k,d] code.
If there exists an [n+1,k+1,d] code, then there exists an [n,k,d] code.
If there exists an [n+1,k,d+1] code, then there exists an [n,k,d] code.

I believe that there are no other assertions of this type (other than formal consequences of the given assertions). None of these assertions are "reversible". Thus an [n,k,d+1] code is "better" than an [n,k,d] code, and so forth for the other three assertions. The parameters of an optimal code cannot be improved!

In practice, one often does not know if a given code is optimal, because one does not always know if there exist codes with parameters [n,k,d+1], [n-1,k,d], [n+1,k+1,d], or [n+1,k,d+1]. If no codes with the latter parameters have (to date) been found, we shall call an [n,k,d] code putatively optimal.