It is expected that you provide an objective function as the 'fun' argument. You are currently using an incorrect function for bayesopt. Additionally, the input objective function for bayesopt accepts an input as a table and outputs an objective value. This information is clearly stated in the documentation of bayesopt. To quote:
"fun accepts x, a 1-by-D table of variable values, and returns objective, a real scalar representing the objective function value fun(x)."
In other words, the way you are using bayesopt is not aligned with its intended usage. I recommend carefully reading the documentation of bayesopt to understand how the function argument should be utilized. It is crucial to provide an objective function for the function argument.